Chat functions - part 2
This commit is contained in:
1 parent
4eaf7fbc62
commit
e01df06789
2 files changed
+104
-9
No files matched your search
+43
-6
@@ -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;
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user