Send Message With Buttons
Request#
You need to send a POST request to:
https://yoai.yophone.com/api/pub/sendMessageRequest body params format (JSON)#
to(required):
The unique identifier for the target chat or the username of the target channel.text(required):
The text of the message to be sent.buttons(required):
An object containing the button configuration.grid(optional):
Number of buttons per row (default is 1).options(optional):
A list of {label:"label","value":"value"} objects.inline_buttons(optional):
A list of {label:"label", "data":"data", "url":"url"} objects to select up to 20 options.
Behavior of Inline Buttons#
If you pass a
urlininline_buttons, clicking the button will open the specified webpage.If you pass a
datafield ininline_buttons, clicking the button will trigger acallbackDataevent, which you can listen to using:myBot.on("callbackData", (ctx) => console.log(ctx.callbackData));Here,
ctx.callbackDatawill contain the value of thedatafield from the clicked button.
Request example (POST):#
Expecting Message format#
{ "to": "123456789", "text": "Choose an option:", "buttons": { "grid": 2, "options": [ { "label": "Option 1", "value": "option_1" }, { "label": "Option 2", "value": "option_2" } ], "inline_buttons": [ { "label": "Visit Website", "url": "https://example.com" }, { "label": "More Info", "data": "more_info" } ] }}Request example#
curl -X POST https://yoai.yophone.com/api/pub/sendMessage \-H "Content-Type: application/json" \-H "X-YoAI-API-Key: your YoAI api token" \-d '{ "to": "123456789", "text": "Choose an option:", "buttons": { "grid": 2, "options": [ { "label": "Option 1", "value": "option_1" }, { "label": "Option 2", "value": "option_2" } ], "inline_buttons": [ { "label": "Visit Website", "url": "https://example.com" }, { "label": "More Info", "data": "more_info" } ] }}'Response Example:#
The response is JSON data with status code 200
Message response format#
{ "success": true, "code": 200, "data": {}}