Skip to content

Commit

Permalink
Merge pull request #99 from green-api/SW-2546
Browse files Browse the repository at this point in the history
Add new function sendPoll
  • Loading branch information
Amele9 authored Nov 8, 2023
2 parents 0fd928c + 10763db commit 94f3956
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/utils/MessageAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,43 @@ class MessageAPI {
return response.data
}

/** Send text message to chat or phone. Method call adds message to sending queue
*
* @param {String} chatId - chat id using Whatsapp format ([email protected] - for private messages).
* Mandatory if phoneNumber is empty
* @param {String} phoneNumber - number ([email protected] - for private messages).
* @param {String} message - text message
* @param {array} options - array of objects
* @param {boolean} multipleAnswers - allow answers
* @param {String} quotedMessageId - id of message
*/

async sendPoll(chatId, phoneNumber, message, options, multipleAnswers = null, quotedMessageId = null) {
CommonUtils.validateChatIdPhoneNumber(chatId, phoneNumber);
CommonUtils.validateString('message', message);
CommonUtils.validateArray('options', options);

const method = 'sendPoll';

const postData = {
'message': message,
'options': options,
};

if (multipleAnswers !== null) {
postData['multipleAnswers'] = multipleAnswers;
}
if (quotedMessageId !== null) {
postData['quotedMessageId'] = quotedMessageId;
}

this.addChadIdParam(postData, chatId);
this.addPhoneParam(postData, phoneNumber);

const response = await axios.post(CommonUtils.generateMethodURL(this._restAPI.params, method), postData);
return response.data
}

/** Send buttons message to chat. Method call adds message to sending queue
*
* @param {String} chatId - chat id using Whatsapp format ([email protected] - for private messages).
Expand Down

0 comments on commit 94f3956

Please sign in to comment.