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 2 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
31 changes: 31 additions & 0 deletions src/utils/MessageAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,37 @@ 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).
* @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
andreyMalyshkin marked this conversation as resolved.
Show resolved Hide resolved
*/
Amele9 marked this conversation as resolved.
Show resolved Hide resolved

async sendPoll(chatId, phoneNumber, message, options, multipleAnswers, quotedMessageId) {
Amele9 marked this conversation as resolved.
Show resolved Hide resolved
CommonUtils.validateChatIdPhoneNumber(chatId, phoneNumber);
CommonUtils.validateString('message', message);
CommonUtils.validateArray('options' , options);
Amele9 marked this conversation as resolved.
Show resolved Hide resolved

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,
'multipleAnswers' : multipleAnswers,
'quotedMessageId' : quotedMessageId,
};
andreyMalyshkin marked this conversation as resolved.
Show resolved Hide resolved

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

const response = await axios__default["default"].post(CommonUtils.generateMethodURL(this._restAPI.params, method), postData);
andreyMalyshkin marked this conversation as resolved.
Show resolved Hide resolved
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