Merge branch 'develop' into main
build.yaml (push) Invalid workflow file

# Conflicts:
#	.dockerignore
#	.gitignore
This commit is contained in:
allburov committed 2022-08-14 09:05:31 +03:00
commit 23a73b4313
10 files changed
+20979 -4124

No files matched your search

+40
View File
@@ -0,0 +1,40 @@
name: Release
on:
push:
tags:
- "*"
jobs:
deploy-docker:
runs-on: ubuntu-latest
needs: deploy-pypi
steps:
- uses: actions/checkout@v2
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: allburov/whatsapp-http-api
flavor: latest=true
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
- name: Login to image repository
if: github.ref_type == 'tag'
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
file: Dockerfile
push: ${{ github.ref_type == 'tag' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
+1 -1
View File
@@ -1,4 +1,4 @@
FROM node:10
FROM node:15
# Chrome
RUN apt-get update \
&& apt-get install -y wget gnupg \
+8
View File
@@ -0,0 +1,8 @@
build:
docker build . -t allburov/whatsapp-http-api
run:
docker run -it -v `pwd`/tokens:/app/tokens -p 127.0.0.1:3000:3000/tcp allburov/whatsapp-http-api
push:
docker push allburov/whatsapp-http-api
+5
View File
@@ -44,6 +44,7 @@ docker pull allburov/whatsapp-http-api
Run WhatsApp HTTP API:
```bash
docker pull allburov/whatsapp-http-api
docker run -it -v `pwd`/tokens:/app/tokens -p 127.0.0.1:3000:3000/tcp allburov/whatsapp-http-api
```
@@ -60,6 +61,10 @@ Let's try to send a message:
```bash
# Phone without +
# Using GET
curl "http://localhost:3000/api/sendText?phone=79776772457&text=Hello+from+WhatsApp+HTTP+API+Free!"
# Using POST
export PHONE=79776772457
curl -d "{\"chatId\": \"${PHONE}@c.us\", \"text\": \"Hello from WhatsApp HTTP API Free\" }" -H "Content-Type: application/json" -X POST http://localhost:3000/api/sendText
```
+20884 -4099
View File
File diff suppressed because it is too large. Load diff
+12 -12
View File
@@ -21,26 +21,26 @@
"test:e2e": "jest --config ./test/jest-e2e.json"
},
"dependencies": {
"@nestjs/common": "^7.0.0",
"@nestjs/common": "^9.0.9",
"@nestjs/config": "^0.5.0",
"@nestjs/core": "^7.0.0",
"@nestjs/platform-express": "^7.0.0",
"@nestjs/core": "^9.0.9",
"@nestjs/platform-express": "^9.0.9",
"@nestjs/serve-static": "^2.1.3",
"@nestjs/swagger": "^4.6.1",
"@nestjs/swagger": "^6.0.5",
"class-validator": "^0.12.2",
"del": "^6.0.0",
"mime-types": "^2.1.27",
"reflect-metadata": "^0.1.13",
"requestretry": "^4.1.1",
"rimraf": "^3.0.2",
"rxjs": "^6.5.4",
"rxjs": "^7.1.0",
"swagger-ui-express": "^4.1.4",
"venom-bot": "^2.2.3"
"venom-bot": "^4.2.7"
},
"devDependencies": {
"@nestjs/cli": "^7.0.0",
"@nestjs/schematics": "^7.0.0",
"@nestjs/testing": "^7.0.0",
"@nestjs/cli": "^9.0.0",
"@nestjs/schematics": "^9.0.1",
"@nestjs/testing": "^9.0.9",
"@types/express": "^4.17.3",
"@types/jest": "26.0.10",
"@types/node": "^13.9.1",
@@ -55,9 +55,9 @@
"supertest": "^4.0.2",
"ts-jest": "26.2.0",
"ts-loader": "^6.2.1",
"ts-node": "9.0.0",
"tsconfig-paths": "^3.9.0",
"typescript": "^3.7.4"
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.1.0",
"typescript": "4.7.4"
},
"jest": {
"moduleFileExtensions": [
+20 -2
View File
@@ -1,4 +1,4 @@
import {Body, Controller, Inject, NotImplementedException, Post} from '@nestjs/common';
import {Body, Controller, Get, Inject, NotImplementedException, Post, Query} from '@nestjs/common';
import {ApiOperation, ApiTags} from "@nestjs/swagger";
import {
Chat,
@@ -12,6 +12,15 @@ import {
} from "./all.dto";
import {Whatsapp} from "venom-bot";
const SUFFIX_DIRECT_MESSAGE = "@c.us"
function ensureSuffix(phone){
if (phone.endsWith(SUFFIX_DIRECT_MESSAGE)){
return phone
}
return phone + SUFFIX_DIRECT_MESSAGE
}
@Controller('api')
@ApiTags('chatting')
export class ChattingController {
@@ -23,10 +32,19 @@ export class ChattingController {
return this.whatsapp.sendContactVcard(message.chatId, message.contactsId, message.name)
}
@Get('/sendText')
@ApiOperation({summary: 'Send a text message'})
sendTextGet(
@Query('phone') phone: string,
@Query('text') text: string,
) {
return this.whatsapp.sendText(ensureSuffix(phone), text)
}
@Post('/sendText')
@ApiOperation({summary: 'Send a text message'})
sendText(@Body() message: MessageText) {
return this.whatsapp.sendText(message.chatId, message.text)
return this.whatsapp.sendText(ensureSuffix(message.chatId), message.text)
}
@Post('/sendLocation')
+3 -4
View File
@@ -1,4 +1,4 @@
import {Logger, Module} from '@nestjs/common';
import {ConsoleLogger, Logger, Module} from '@nestjs/common';
import {ChattingController} from './api/chatting.controller';
import {DeviceController} from "./api/device.controller";
import {whatsappProvider, WhatsappService} from "./whatsapp.service";
@@ -9,12 +9,11 @@ import {ServeStaticModule} from "@nestjs/serve-static";
@Module({
imports: [
WhatsappConfigService,
ConfigModule.forRoot({
isGlobal: true,
}),
ServeStaticModule.forRootAsync({
imports: [WhatsappConfigService],
imports: [],
extraProviders: [WhatsappConfigService],
inject: [WhatsappConfigService],
useFactory: (config: WhatsappConfigService) => {
@@ -26,7 +25,7 @@ import {ServeStaticModule} from "@nestjs/serve-static";
}),
],
controllers: [ChattingController, DeviceController, ScreenshotController],
providers: [whatsappProvider, WhatsappService, Logger, WhatsappConfigService],
providers: [whatsappProvider, WhatsappService, ConsoleLogger, WhatsappConfigService],
})
export class AppModule {
}
+5 -6
View File
@@ -1,5 +1,5 @@
import {create, Message, Whatsapp} from "venom-bot";
import {Inject, Injectable, Logger, OnApplicationShutdown} from "@nestjs/common";
import {ConsoleLogger, Inject, Injectable, Logger, OnApplicationShutdown} from "@nestjs/common";
import {ConfigService} from "@nestjs/config";
import * as path from "path";
import {WhatsappConfigService} from "./config.service";
@@ -21,9 +21,7 @@ export const whatsappProvider = {
(base64Qr, asciiQR) => {
console.log(asciiQR);
},
(statusFind) => {
console.log(statusFind);
},
undefined,
{
headless: true,
devtools: false,
@@ -34,8 +32,9 @@ export const whatsappProvider = {
autoClose: 60000,
createPathFileToken: true,
puppeteerOptions: {},
multidevice: false,
}
),
)
}
const ONMESSAGE_HOOK = "onMessage"
@@ -63,7 +62,7 @@ export class WhatsappService implements OnApplicationShutdown {
constructor(
@Inject('WHATSAPP') private whatsapp: Whatsapp,
private config: WhatsappConfigService,
private log: Logger,
private log: ConsoleLogger,
) {
this.log.setContext('WhatsappService')
+1
View File
@@ -0,0 +1 @@
{"openapi":"3.0.0","info":{"title":"WhatsApp HTTP API","description":"WhatsApp HTTP API that you can configure in a click","version":"1.0","contact":{}},"tags":[{"name":"device","description":"Device information"},{"name":"chatting","description":"Chat methods"}],"servers":[],"components":{"securitySchemes":{"api_key":{"type":"apiKey","in":"header","name":"X-VENOM-TOKEN","description":"Your secret key"}},"schemas":{"MessageContactVcard":{"type":"object","properties":{"chatId":{"type":"string","example":"791231234567@c.us"},"contactsId":{"type":"string"},"name":{"type":"string"}},"required":["chatId","contactsId","name"]},"MessageText":{"type":"object","properties":{"chatId":{"type":"string","example":"791231234567@c.us"},"text":{"type":"string"}},"required":["chatId","text"]},"MessageLocation":{"type":"object","properties":{"chatId":{"type":"string","example":"791231234567@c.us"},"latitude":{"type":"string"},"longitude":{"type":"string"},"title":{"type":"string"}},"required":["chatId","latitude","longitude","title"]},"MessageLinkPreview":{"type":"object","properties":{"chatId":{"type":"string","example":"791231234567@c.us"},"url":{"type":"string"},"title":{"type":"string"}},"required":["chatId","url","title"]},"MessageImage":{"type":"object","properties":{"chatId":{"type":"string","example":"791231234567@c.us"},"path":{"type":"string"},"filename":{"type":"string"},"caption":{"type":"string"}},"required":["chatId","path","filename","caption"]},"MessageFile":{"type":"object","properties":{"chatId":{"type":"string","example":"791231234567@c.us"},"path":{"type":"string"},"filename":{"type":"string"},"caption":{"type":"string"}},"required":["chatId","path","filename","caption"]},"MessageReply":{"type":"object","properties":{"chatId":{"type":"string","example":"791231234567@c.us"},"reply_to":{"type":"string","example":"message.id"},"text":{"type":"string"}},"required":["chatId","reply_to","text"]},"Chat":{"type":"object","properties":{"chatId":{"type":"string","example":"791231234567@c.us"}},"required":["chatId"]}}},"paths":{"/api/sendContactVcard":{"post":{"operationId":"ChattingController_sendContactVcard","parameters":[],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/MessageContactVcard"}}}},"responses":{"201":{"description":"","content":{"application/json":{"schema":{"type":"object"}}}}},"tags":["chatting"]}},"/api/sendText":{"post":{"operationId":"ChattingController_sendText","summary":"Send a text message","parameters":[],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/MessageText"}}}},"responses":{"201":{"description":"","content":{"application/json":{"schema":{"type":"object"}}}}},"tags":["chatting"]}},"/api/sendLocation":{"post":{"operationId":"ChattingController_sendLocation","parameters":[],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/MessageLocation"}}}},"responses":{"201":{"description":"","content":{"application/json":{"schema":{"type":"object"}}}}},"tags":["chatting"]}},"/api/sendLinkPreview":{"post":{"operationId":"ChattingController_sendLinkPreview","parameters":[],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/MessageLinkPreview"}}}},"responses":{"201":{"description":"","content":{"application/json":{"schema":{"type":"object"}}}}},"tags":["chatting"]}},"/api/sendImage":{"post":{"operationId":"ChattingController_sendImage","summary":"NOT IMPLEMENTED YET","parameters":[],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/MessageImage"}}}},"responses":{"201":{"description":"","content":{"application/json":{"schema":{"type":"object"}}}}},"tags":["chatting"]}},"/api/sendFile":{"post":{"operationId":"ChattingController_sendFile","summary":"NOT IMPLEMENTED YET","parameters":[],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/MessageFile"}}}},"responses":{"201":{"description":"","content":{"application/json":{"schema":{"type":"object"}}}}},"tags":["chatting"]}},"/api/reply":{"post":{"operationId":"ChattingController_reply","summary":"Reply to a text message","parameters":[],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/MessageReply"}}}},"responses":{"201":{"description":"","content":{"application/json":{"schema":{"type":"object"}}}}},"tags":["chatting"]}},"/api/sendSeen":{"post":{"operationId":"ChattingController_sendSeen","parameters":[],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Chat"}}}},"responses":{"201":{"description":""}},"tags":["chatting"]}},"/api/startTyping":{"post":{"operationId":"ChattingController_startTyping","parameters":[],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Chat"}}}},"responses":{"201":{"descriptiLine truncated