Answer the question
In order to leave comments, you need to log in
InlineKeyboardMarkup Telegram. What could I be missing?
Wrote a simple button generator. At the input we give $tg->GenKeyboard2("#string1# #string1# ? #string2# #string2#");
(the code)
public function GenKeyboard2($data)
{
$data = trim($data);
$mas = explode("#", $data);
$i=0;$j=0;$j_=0;
foreach ($mas as $key => $value) {
if(!empty(trim($value)))
{
if(strpos($value, "?")===FALSE)
{
$arInfo["inline_keyboard"][$i][$j]["text"] = $value;
$j++;
}
else { $i++; $j=0; }
}
}
return $arInfo;
}
array(1) {
["inline_keyboard"]=>
array(2) {
[0]=>
array(2) {
[0]=>
array(1) {
["text"]=>
string(13) "строка1"
}
[1]=>
array(1) {
["text"]=>
string(13) "строка1"
}
}
[1]=>
array(2) {
[0]=>
array(1) {
["text"]=>
string(13) "строка2"
}
[1]=>
array(1) {
["text"]=>
string(13) "строка2"
}
}
}
}
public function send($id, $message,$keyboard='')
{
if($keyboard == "DEL"){
$keyboard = array(
'remove_keyboard' => true
);
}
if($keyboard){
$encodedMarkup = json_encode($keyboard);
$data = array(
'chat_id' => $id,
'text' => $message,
'reply_markup' => $encodedMarkup
);
}else{
$data = array(
'chat_id' => $id,
'text' => $message
);
}
$out = $this->request('sendMessage', $data);
return $out;
}
Answer the question
In order to leave comments, you need to log in
can help, I personally wrote this
via NuGet connected Telegram.Bot
and the script itself:
switch (message.Text)
{
case "/btn":
var inlineKeyboard = new InlineKeyboardMarkup(new[]
{
new[]
{
InlineKeyboardButton.WithUrl("link ", "text"),
},
new[]
{
InlineKeyboardButton.WithCallbackData("button2"),
}
});
await Bot.SendTextMessageAsync(message.From.Id, "available buttons",
replyMarkup: inlineKeyboard);
break;
default:
break;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question