Telegram::buildKeyBoard PHP Method

buildKeyBoard() public method

\param $resize Boolean Requests clients to resize the keyboard vertically for optimal fit (e.g., make the keyboard smaller if there are just two rows of buttons). Defaults to false, in which case the custom keyboard is always of the same height as the app's standard keyboard. \param $selective Boolean Use this parameter if you want to show the keyboard to specific users only. Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message. \return the requested keyboard as Json
public buildKeyBoard ( array $options, $onetime = false, $resize = false, $selective = true )
$options array
    public function buildKeyBoard(array $options, $onetime = false, $resize = false, $selective = true)
    {
        $replyMarkup = array('keyboard' => $options, 'one_time_keyboard' => $onetime, 'resize_keyboard' => $resize, 'selective' => $selective);
        $encodedMarkup = json_encode($replyMarkup, true);
        return $encodedMarkup;
    }

Usage Example

Exemplo n.º 1
0
// Set the bot TOKEN
$bot_id = "bot_token";
// Instances the class
$telegram = new Telegram($bot_id);
/* If you need to manually take some parameters
*  $result = $telegram->getData();
*  $text = $result["message"] ["text"];
*  $chat_id = $result["message"] ["chat"]["id"];
*/
// Take text and chat_id from the message
$text = $telegram->Text();
$chat_id = $telegram->ChatID();
if ($text == "/start") {
    $option = array(array("🐮"), array("Git", "Credit"));
    // Create a permanent custom keyboard
    $keyb = $telegram->buildKeyBoard($option, $onetime = false);
    $content = array('chat_id' => $chat_id, 'reply_markup' => $keyb, 'text' => "Welcome to CowBot 🐮 \nPlease type /cowsay or click the Cow button !");
    $telegram->sendMessage($content);
}
if ($text == "/cowsay" || $text == "🐮") {
    $randstring = rand() . sha1(time());
    $cowurl = "http://bangame.altervista.org/cowsay/fortune_image_w.php?preview=" . $randstring;
    $content = array('chat_id' => $chat_id, 'text' => $cowurl);
    $telegram->sendMessage($content);
}
if ($text == "/credit" || $text == "Credit") {
    $reply = "Eleirbag89 Telegram PHP API http://telegrambot.ienadeprex.com \nFrancesco Laurita (for the cowsay script) http://francesco-laurita.info/wordpress/fortune-cowsay-on-php-5";
    $content = array('chat_id' => $chat_id, 'text' => $reply);
    $telegram->sendMessage($content);
}
if ($text == "/git" || $text == "Git") {
All Usage Examples Of Telegram::buildKeyBoard