refactor: remove list and button

This commit is contained in:
Anton Voylenko 2024-12-07 17:11:49 +02:00
commit 33a2f0c121
3 changed files with 16 additions and 40 deletions

View file

@ -62,17 +62,16 @@ docker-compose pull && docker-compose up
| Actions | Status | Sessions | Status | Callbacks | Status | | Actions | Status | Sessions | Status | Callbacks | Status |
| ----------------------------| ------| ----------------------------------------| ------| ----------------------------------------------| ------| | ----------------------------| ------| ----------------------------------------| ------| ----------------------------------------------| ------|
| Send Image Message | ✅ | Initiate session | ✅ | Callback QR code | ✅ | | Send Image Message | ✅ | Initiate session | ✅ | Callback QR code | ✅ |
| Send Video Message | ✅ | Terminate session | ✅ | Callback new message | ✅ | | Send Video Message(requires Google Chrome) | ✅ | Terminate session | ✅ | Callback new message | ✅ |
| Send Audio Message | ✅ | Terminate inactive sessions | ✅ | Callback status change | ✅ | | Send Audio Message | ✅ | Terminate inactive sessions | ✅ | Callback status change | ✅ |
| Send Document Message | ✅ | Terminate all sessions | ✅ | Callback message media attachment | ✅ | | Send Document Message | ✅ | Terminate all sessions | ✅ | Callback message media attachment | ✅ |
| Send File URL | ✅ | Healthcheck | ✅ | | | | Send File URL | ✅ | Restart session | ✅ | | |
| Send Button Message | ✅ | Local test callback | | | | | Send Contact Message | ✅ | Get session status | ✅ | | |
| Send Contact Message | ✅ | | | | | | Send Poll Message | ✅ | Health Check | ✅ | | |
| Send List Message | ✅ | | | | | | Edit Message | ✅ | | | | |
| Set Status | ✅ | | | | | | Set Status | ✅ | | | | |
| Send Button With Media | ✅ | | | | |
| Is On Whatsapp? | ✅ | | | | | | Is On Whatsapp? | ✅ | | | | |
| Download Profile Pic | ✅ | | | | | | Download Profile Picture | ✅ | | | | |
| User Status | ✅ | | | | | | User Status | ✅ | | | | |
| Block/Unblock User | ✅ | | | | | | Block/Unblock User | ✅ | | | | |
| Update Profile Picture | ✅ | | | | | | Update Profile Picture | ✅ | | | | |
@ -88,15 +87,15 @@ docker-compose pull && docker-compose up
| Update Group Subject | ✅ | | | | | | Update Group Subject | ✅ | | | | |
| Update Group Description | ✅ | | | | | | Update Group Description | ✅ | | | | |
3. Handle multiple client sessions (session data saved locally), identified by unique id 1. Handle multiple client sessions (session data saved locally), identified by unique id
4. All endpoints may be secured by a global API key 2. All endpoints may be secured by a global API key
5. On server start, all existing sessions are restored 3. On server start, all existing sessions are restored
6. Set messages automatically as read 4. Set messages automatically as read
7. Disable any of the callbacks 5. Disable any of the callbacks
## Run Locally ## Run Locally

View file

@ -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 { sessions } = require('../sessions')
const { sendErrorResponse } = require('../utils') const { sendErrorResponse } = require('../utils')
@ -30,11 +30,11 @@ const sendMessage = async (req, res) => {
properties: { properties: {
chatId: { chatId: {
type: 'string', 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: { contentType: {
type: 'string', 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: { content: {
type: 'object', 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' } } }, 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' } }, 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' } } }, 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: { Contact: {
value: { chatId: '6281288888888@c.us', contentType: 'Contact', content: { contactId: '6281288888889@c.us' } } 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) messageOut = await client.sendMessage(chatId, location, options)
break 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': { case 'Contact': {
const contactId = content.contactId.endsWith('@c.us') ? content.contactId : `${content.contactId}@c.us` const contactId = content.contactId.endsWith('@c.us') ? content.contactId : `${content.contactId}@c.us`
const contact = await client.getContactById(contactId) const contact = await client.getContactById(contactId)
@ -121,7 +107,6 @@ const sendMessage = async (req, res) => {
default: default:
return sendErrorResponse(res, 400, 'contentType invalid, must be string, MessageMedia, MessageMediaFromURL, Location, Buttons, List, Contact or Poll') return sendErrorResponse(res, 400, 'contentType invalid, must be string, MessageMedia, MessageMediaFromURL, Location, Buttons, List, Contact or Poll')
} }
res.json({ success: true, message: messageOut }) res.json({ success: true, message: messageOut })
} catch (error) { } catch (error) {
console.log(error) console.log(error)

View file

@ -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 { sessions } = require('../sessions')
const { sendErrorResponse } = require('../utils') const { sendErrorResponse } = require('../utils')
@ -418,7 +418,7 @@ const reply = async (req, res) => {
}, },
contentType: { contentType: {
type: 'string', 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: { content: {
type: 'object', type: 'object',
@ -465,14 +465,6 @@ const reply = async (req, res) => {
contentMessage = new Location(content.latitude, content.longitude, content.description) contentMessage = new Location(content.latitude, content.longitude, content.description)
break 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': { case 'Contact': {
const contactId = content.contactId.endsWith('@c.us') ? content.contactId : `${content.contactId}@c.us` const contactId = content.contactId.endsWith('@c.us') ? content.contactId : `${content.contactId}@c.us`
contentMessage = await client.getContactById(contactId) contentMessage = await client.getContactById(contactId)