Простейшая голосовалка на посты в каналы и группы
Простейшая голосовалка на посты в каналы и группы
Отправка сообщения с кнопками голосования (вместо "???????????" указать ID канала)
include_once(DIR_MODULES . 'telegram/telegram.class.php');
$telegram_module = new telegram();
$text ="test";
$plus = json_decode('"'.'\ud83d\udc4d'.'"');
$minus = json_decode('"'.'\ud83d\udc4e'.'"');
$option = array( array($telegram_module->buildInlineKeyboardButton("0 ".$plus,"","cb_vote_plus",""),
$telegram_module->buildInlineKeyboardButton("0 ".$minus,"","cb_vote_minus","")) );
$keyb = $telegram_module->buildInlineKeyBoard($option);
$content = array('chat_id' => "???????????", 'text' => $text, 'reply_markup' => $keyb, 'parse_mode'=>'HTML');
$telegram_module->sendContent($content);
Обработчик callback вызова
if (strpos($callback, 'cb_vote_') !== false) {
$skip = true;
$res = $data["callback_query"]["message"]["text"];
$cmd = explode("_", $callback);
$endpoint = "editMessageText";
$content = array(
'chat_id' => $data["callback_query"]["message"]["chat"]["id"],
'message_id' => $message_id,
'parse_mode' => 'HTML'
);
$plus =intval($data["callback_query"]["message"]["reply_markup"]["inline_keyboard"][0][0]["text"]);
$minus = intval($data["callback_query"]["message"]["reply_markup"]["inline_keyboard"][0][1]["text"]);
if ($cmd[2] == 'plus')
{
$plus = $plus + 1;
}
if ($cmd[2] == 'minus')
{
$minus = $minus + 1;
}
$plus_i = json_decode('"'.'\ud83d\udc4d'.'"');
$minus_i = json_decode('"'.'\ud83d\udc4e'.'"');
$option = array( array($this->buildInlineKeyboardButton($text=$plus." ".$plus_i,"","cb_vote_plus",""),
$this->buildInlineKeyboardButton($text=$minus." ".$minus_i,"","cb_vote_minus","")) );
$keyb = $this->buildInlineKeyBoard($option);
$content['text'] = $res;
$content['reply_markup'] = $keyb;
$this->sendContent($content, $endpoint);
}
Киров, Россия
На форуме: Eraser