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

Add new function sendPoll #99

Merged
merged 6 commits into from
Nov 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
*/
Amele9 marked this conversation as resolved.
Show resolved Hide resolved

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

Amele9 marked this conversation as resolved.
Show resolved Hide resolved
const method = 'sendPoll';

const postData = {
Amele9 marked this conversation as resolved.
Show resolved Hide resolved
'message': message,
'options': options,
};
andreyMalyshkin marked this conversation as resolved.
Show resolved Hide resolved

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
Loading