Reputation: 95
I'm using MS Bot Framework. I want to sen custom keyboard to user, so i try to reply message with this JSON:
public async Task<Message> Post([FromBody]Message message)
{
var connector = new ConnectorClient();
if (message.Type == "Message")
{
var replyMessage = message.CreateReplyMessage($"You sent message");
replyMessage.ChannelData = @"
{
""method"": ""sendMessage"",
""parameters"":
{
""reply_markup"":
{
""keyboard"":[[[""1""],[""2""]],[[""3""]],[[""4""],[""5""],[""6""]]]
}
}
}";
return replyMessage;
}
else
{
return HandleSystemMessage(message);
}
}
But nothing happens. For example, this message with sticker works fine:
replyMessage.ChannelData = @"
{
""method"": ""sendSticker"",
""parameters"":
{
""sticker"":
{
""url"": ""https://upload.wikimedia.org/wikipedia/commons/3/33/LittleCarron.gif"",
""mediaType"": ""image/gif""
}
}
}";
I think that the problem is in "keyboard" part, somewhere in array.
Upvotes: 2
Views: 2859
Reputation: 1980
Add another bracket to your keyboard
.( one more array) like this:
""keyboard"":[[[""1""],[""2""]],[[""3""]],[[""4""],[""5""],[""6""]]]
know there is triple array inside each other instead of two of your code.
a part of working code:
$keyboard = [
'keyboard' =>
[[['text' => '1'], ['text' => '2']], [['text' => '3']], [['text' => '4'], ['text' => '5'], ['text' => '6']]],
'one_time_keyboard' => true,
];
$markup = json_encode($keyboard, true);
$data = [
'chat_id' => sender_user_id($update),
'text' => 'JUST A TEXT',
'reply_markup' => $markup];
$ch = curl_init();
$url = 'https://api.telegram.org/bot' . BOT_TOKEN . '/SendMessage';
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, ($data));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
curl_close($ch);
Upvotes: 0