From e01df0678956b3a17296946c05f9aafbad772ada Mon Sep 17 00:00:00 2001 From: allburov Date: Wed, 21 Oct 2020 11:56:11 +0700 Subject: [PATCH] Chat functions - part 2 --- src/api/all.dto.ts | 49 +++++++++++++++++++++++---- src/api/chattingController.ts | 64 +++++++++++++++++++++++++++++++++-- 2 files changed, 104 insertions(+), 9 deletions(-) diff --git a/src/api/all.dto.ts b/src/api/all.dto.ts index 3e8b0f8b..6839e6ea 100644 --- a/src/api/all.dto.ts +++ b/src/api/all.dto.ts @@ -1,10 +1,47 @@ -export class MessageOut { - readonly chatId: string; - readonly text: string; +export class Chat { + chatId: string; +} + +export class MessageContactVcard { + chatId: string; + contactsId: string; + name: string +} + +export class MessageText { + chatId: string; + text: string; } export class MessageReply { - readonly chatId: string; - readonly text: string; - readonly reply_to: string; + chatId: string; + text: string; + reply_to: string; } + +export class MessageLocation { + chatId: string; + latitude: string; + longitude: string; + title: string; +} + +export class MessageImage { + chatId: string; + path: string; + filename: string; + caption: string; +} + +export class MessageFile { + chatId: string; + path: string; + filename: string; + caption: string; +} + +export class MessageLinkPreview { + chatId: string; + url: string; + title: string; +} \ No newline at end of file diff --git a/src/api/chattingController.ts b/src/api/chattingController.ts index 65af601a..54c590ab 100644 --- a/src/api/chattingController.ts +++ b/src/api/chattingController.ts @@ -1,6 +1,15 @@ -import {Body, Controller, Inject, Post} from '@nestjs/common'; +import {Body, Controller, Inject, NotImplementedException, Post} from '@nestjs/common'; import {ApiOperation, ApiTags} from "@nestjs/swagger"; -import {MessageOut, MessageReply} from "./all.dto"; +import { + Chat, + MessageContactVcard, + MessageFile, + MessageImage, + MessageLinkPreview, + MessageLocation, + MessageReply, + MessageText +} from "./all.dto"; import {Whatsapp} from "venom-bot"; @Controller('api') @@ -9,15 +18,64 @@ export class ChattingController { constructor(@Inject('WHATSAPP') private whatsapp: Whatsapp) { } + @Post('/sendContactVcard') + sendContactVcard(@Body() message: MessageContactVcard) { + return this.whatsapp.sendContactVcard(message.chatId, message.contactsId, message.name) + } + @Post('/sendText') @ApiOperation({summary: 'Send a text message'}) - sendText(@Body() message: MessageOut) { + sendText(@Body() message: MessageText) { return this.whatsapp.sendText(message.chatId, message.text) } + @Post('/sendLocation') + sendLocation(@Body() message: MessageLocation) { + return this.whatsapp.sendLocation(message.chatId, message.latitude, message.longitude, message.title) + } + + @Post('/sendLinkPreview') + sendLinkPreview(@Body() message: MessageLinkPreview) { + return this.whatsapp.sendLinkPreview(message.chatId, message.url, message.title) + } + + @Post('/sendImage') + @ApiOperation({summary: 'NOT IMPLEMENTED YET'}) + sendImage(@Body() message: MessageImage) { + throw new NotImplementedException(); + // TODO: Accept image URL, download it and then send with path + return this.whatsapp.sendImage(message.chatId, message.path, message.filename, message.caption) + } + + @Post('/sendFile') + @ApiOperation({summary: 'NOT IMPLEMENTED YET'}) + sendFile(@Body() message: MessageFile) { + throw new NotImplementedException(); + // TODO: Accept File URL, download it and then send with path + return this.whatsapp.sendFile(message.chatId, message.path, message.filename, message.caption) + } + @Post('/reply') @ApiOperation({summary: 'Reply to a text message'}) reply(@Body() message: MessageReply) { return this.whatsapp.reply(message.chatId, message.text, message.reply_to, []) } + + @Post('/sendSeen') + sendSeen(@Body() chat: Chat) { + return this.whatsapp.sendSeen(chat.chatId) + } + + @Post('/startTyping') + startTyping(@Body() chat: Chat) { + // It's infinitive action + this.whatsapp.startTyping(chat.chatId) + return true + } + + @Post('/stopTyping') + stopTyping(@Body() chat: Chat) { + this.whatsapp.stopTyping(chat.chatId) + return true + } }