Skip to content

Commit

Permalink
fix: Fixed send-buttons endpoint (#711)
Browse files Browse the repository at this point in the history
  • Loading branch information
dudanogueira committed May 10, 2022
1 parent 94acad9 commit 794e00f
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/controller/messageController.js
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
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

0 comments on commit 794e00f

Please sign in to comment.