Skip to content

Commit 42fa4dd

Browse files
committed
Implenting sendMessageWithReplyKeyboard method
1 parent 2362e2c commit 42fa4dd

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/UniversalTelegramBot.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,39 @@ bool UniversalTelegramBot::sendMessage(String chat_id, String text, String reply
238238
// if (sent==false) Serial.println("Message not delivered");
239239
}
240240

241+
bool UniversalTelegramBot::sendMessageWithReplyKeyboard(String chat_id, String text, String reply_markup, String keyboard, bool resize, bool oneTime, bool selective) {
242+
243+
244+
DynamicJsonBuffer jsonBuffer;
245+
JsonObject& payload = jsonBuffer.createObject();
246+
payload["chat_id"] = chat_id;
247+
payload["text"] = text;
248+
JsonObject& replyMarkup = payload.createNestedObject("reply_markup");
249+
250+
// Reply keyboard is an array of arrays.
251+
// Outer array represents rows
252+
// Inner arrays represents columns
253+
// This example "ledon" and "ledoff" are two buttons on the top row
254+
// and "status is a single button on the next row"
255+
DynamicJsonBuffer keyboardBuffer;
256+
replyMarkup["keyboard"] = keyboardBuffer.parseArray(keyboard);
257+
258+
//Telegram defaults these values to false, so to decrease the size of the payload we will only send them if needed
259+
if(resize){
260+
replyMarkup["resize_keyboard"] = resize;
261+
}
262+
263+
if(oneTime){
264+
replyMarkup["one_time_keyboard"] = oneTime;
265+
}
266+
267+
if(selective){
268+
replyMarkup["selective"] = selective;
269+
}
270+
271+
return sendPostMessage(payload);
272+
}
273+
241274
/***********************************************************************
242275
* SendPostMessage - function to send message to telegram *
243276
* (Arguments to pass: chat_id, text to transmit and markup(optional)) *

src/UniversalTelegramBot.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class UniversalTelegramBot
5050
String sendPostToTelegram(String command, JsonObject& payload);
5151
bool getMe();
5252
bool sendMessage(String chat_id, String text, String reply_markup);
53+
bool sendMessageWithReplyKeyboard(String chat_id, String text, String reply_markup, String keyboard, bool resize = false, bool oneTime = false, bool selective = false);
5354
bool sendPostMessage(JsonObject& payload);
5455
int getUpdates(long offset);
5556
telegramMessage messages[HANDLE_MESSAGES];

0 commit comments

Comments
 (0)