Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fixed send-buttons endpoint #711

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 4 additions & 8 deletions src/controller/messageController.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,23 +174,19 @@ export async function sendLocation(req, res) {
}

export async function sendButtons(req, res) {
const { phone, message = null, title, footer = null, dynamic_reply = true, buttons } = req.body;
const { phone, message, options } = req.body;

try {
let results = [];

for (const contact of phone) {
results.push(
await req.client.sendMessageOptions(contact, message, {
title: title,
footer: footer,
isDynamicReplyButtonsMsg: dynamic_reply,
dynamicReplyButtons: buttons,
})
await req.client.sendText(contact, message, options)
);
}


if (results.length === 0) return returnError(req, res, 'Error sending message');
if (results.length === 0) return returnError(req, res, 'Error sending message with buttons');

returnSucess(res, phone, results);
} catch (error) {
Expand Down
88 changes: 88 additions & 0 deletions src/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -4848,6 +4848,41 @@
"deprecated": false
}
},
"/send-buttons": {
"post": {
"tags": [
"Send Message"
],
"summary": "Send Message Button",
"description": "Envia uma mensagem de botões para um número de telefone. ",
"operationId": "SendMessageWithButton",
"parameters": [],
"requestBody": {
"description": "",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/SendMessageRequestWithButton"
}
}
},
"required": true
},
"responses": {
"201": {
"description": "Created",
"headers": {},
"content": {}
},
"400": {
"description": "Bad Request",
"headers": {},
"content": {}
}
},
"deprecated": false
}
},
"/forwardMessages": {
"post": {
"tags": ["Send Message"],
Expand Down Expand Up @@ -15223,6 +15258,59 @@
"isGroup": false
}
},
"SendMessageRequestWithButton": {
"title": "SendMessageRequestWithButton",
"required": [
"phone",
"message",
"options"
],
"type": "object",
"properties": {
"phone": {
"type": "string"
},
"message": {
"type": "string"
},
"options": {
"type": "any"
}
},
"example": {
"phone": "554498005216",
"message": "Hello World",
"options": {
"useTemplateButtons": "true",
"buttons": [
{
"id": "1",
"text": "Text 1"
},
{
"id": "2",
"phoneNumber": "554498005216",
"text": "Call Us"
},
{
"id": "3",
"url": "https://wppconnect-team.github.io/",
"text": "Long Life WPPCONNECT"
},
{
"id": "4",
"text": "Text 4"
},
{
"id": "5",
"text": "Text 5"
}
],
"title": "Title text",
"footer": "Footer text"
}
}
},
"ForwardMessages(Encaminharmensagem)Request": {
"title": "ForwardMessages(Encaminharmensagem)Request",
"required": ["phone", "messageId"],
Expand Down