-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #99 from green-api/SW-2546
Add new function sendPoll
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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). | ||
|