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
// 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") {
Esempio n. 2
0
*/
// Take text and chat_id from the message
$text = $telegram->Text();
$chat_id = $telegram->ChatID();
// Check if the text is a command
if (!is_null($text) && !is_null($chat_id)) {
    if ($text == "/test") {
        if ($telegram->messageFromGroup()) {
            $reply = "Chat Group";
        } else {
            $reply = "Private Chat";
        }
        // Create option for the custom keyboard. Array of array string
        $option = array(array("A", "B"), array("C", "D"));
        // Get the keyboard
        $keyb = $telegram->buildKeyBoard($option);
        $content = array('chat_id' => $chat_id, 'reply_markup' => $keyb, 'text' => $reply);
        $telegram->sendMessage($content);
    }
    if ($text == "/git") {
        $reply = "Check me on GitHub: https://github.com/Eleirbag89/TelegramBotPHP";
        // Build the reply array
        $content = array('chat_id' => $chat_id, 'text' => $reply);
        $telegram->sendMessage($content);
    }
    if ($text == "/img") {
        // Load a local file to upload. If is already on Telegram's Servers just pass the resource id
        $img = curl_file_create('test.png', 'image/png');
        $content = array('chat_id' => $chat_id, 'photo' => $img);
        $telegram->sendPhoto($content);
        //Download the file just sended