refactor: remove list and button
This commit is contained in:
parent
8263ffb942
commit
33a2f0c121
3 changed files with 16 additions and 40 deletions
|
|
@ -1,4 +1,4 @@
|
|||
const { MessageMedia, Location, Buttons, List, Poll } = require('whatsapp-web.js')
|
||||
const { MessageMedia, Location, Poll } = require('whatsapp-web.js')
|
||||
const { sessions } = require('../sessions')
|
||||
const { sendErrorResponse } = require('../utils')
|
||||
|
||||
|
|
@ -30,11 +30,11 @@ const sendMessage = async (req, res) => {
|
|||
properties: {
|
||||
chatId: {
|
||||
type: 'string',
|
||||
description: 'The Chat id which contains the message (Group or Individual)',
|
||||
description: 'The chat id which contains the message (Group or Individual)',
|
||||
},
|
||||
contentType: {
|
||||
type: 'string',
|
||||
description: 'The type of message content, must be one of the following: string, MessageMedia, MessageMediaFromURL, Location, Contact, Poll, Buttons, or List',
|
||||
description: 'The type of message content, must be one of the following: string, MessageMedia, MessageMediaFromURL, Location, Contact or Poll',
|
||||
},
|
||||
content: {
|
||||
type: 'object',
|
||||
|
|
@ -51,10 +51,6 @@ const sendMessage = async (req, res) => {
|
|||
MessageMedia: { value: { chatId: '6281288888888@c.us', contentType: 'MessageMedia', content: { mimetype: 'image/jpeg', data: 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=', filename: 'image.jpg' } } },
|
||||
MessageMediaFromURL: { value: { chatId: '6281288888888@c.us', contentType: 'MessageMediaFromURL', content: 'https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=Example' } },
|
||||
Location: { value: { chatId: '6281288888888@c.us', contentType: 'Location', content: { latitude: -6.2, longitude: 106.8, description: 'Jakarta' } } },
|
||||
Buttons: { value: { chatId: '6281288888888@c.us', contentType: 'Buttons', content: { body: 'Hello World!', buttons: [{ body: 'button 1' }], title: 'Hello World!', footer: 'Hello World!' } } },
|
||||
List: {
|
||||
value: { chatId: '6281288888888@c.us', contentType: 'List', content: { body: 'Hello World!', buttonText: 'Hello World!', sections: [{ title: 'sectionTitle', rows: [{ id: 'customId', title: 'ListItem2', description: 'desc' }, { title: 'ListItem2' }] }], title: 'Hello World!', footer: 'Hello World!' } }
|
||||
},
|
||||
Contact: {
|
||||
value: { chatId: '6281288888888@c.us', contentType: 'Contact', content: { contactId: '6281288888889@c.us' } }
|
||||
},
|
||||
|
|
@ -97,16 +93,6 @@ const sendMessage = async (req, res) => {
|
|||
messageOut = await client.sendMessage(chatId, location, options)
|
||||
break
|
||||
}
|
||||
case 'Buttons': {
|
||||
const buttons = new Buttons(content.body, content.buttons, content.title, content.footer)
|
||||
messageOut = await client.sendMessage(chatId, buttons, options)
|
||||
break
|
||||
}
|
||||
case 'List': {
|
||||
const list = new List(content.body, content.buttonText, content.sections, content.title, content.footer)
|
||||
messageOut = await client.sendMessage(chatId, list, options)
|
||||
break
|
||||
}
|
||||
case 'Contact': {
|
||||
const contactId = content.contactId.endsWith('@c.us') ? content.contactId : `${content.contactId}@c.us`
|
||||
const contact = await client.getContactById(contactId)
|
||||
|
|
@ -121,7 +107,6 @@ const sendMessage = async (req, res) => {
|
|||
default:
|
||||
return sendErrorResponse(res, 400, 'contentType invalid, must be string, MessageMedia, MessageMediaFromURL, Location, Buttons, List, Contact or Poll')
|
||||
}
|
||||
|
||||
res.json({ success: true, message: messageOut })
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
const { MessageMedia, Location, Buttons, List, Poll } = require('whatsapp-web.js')
|
||||
const { MessageMedia, Location, Poll } = require('whatsapp-web.js')
|
||||
const { sessions } = require('../sessions')
|
||||
const { sendErrorResponse } = require('../utils')
|
||||
|
||||
|
|
@ -418,7 +418,7 @@ const reply = async (req, res) => {
|
|||
},
|
||||
contentType: {
|
||||
type: 'string',
|
||||
description: 'The type of message content, must be one of the following: string, MessageMedia, MessageMediaFromURL, Location, Contact, Poll, Buttons, or List',
|
||||
description: 'The type of message content, must be one of the following: string, MessageMedia, MessageMediaFromURL, Location, Contact or Poll',
|
||||
},
|
||||
content: {
|
||||
type: 'object',
|
||||
|
|
@ -465,14 +465,6 @@ const reply = async (req, res) => {
|
|||
contentMessage = new Location(content.latitude, content.longitude, content.description)
|
||||
break
|
||||
}
|
||||
case 'Buttons': {
|
||||
contentMessage = new Buttons(content.body, content.buttons, content.title, content.footer)
|
||||
break
|
||||
}
|
||||
case 'List': {
|
||||
contentMessage = new List(content.body, content.buttonText, content.sections, content.title, content.footer)
|
||||
break
|
||||
}
|
||||
case 'Contact': {
|
||||
const contactId = content.contactId.endsWith('@c.us') ? content.contactId : `${content.contactId}@c.us`
|
||||
contentMessage = await client.getContactById(contactId)
|
||||
|
|
|
|||
Loading…
Reference in a new issue