webdevask.com

Menu

  • Home
  • New
  • Add question

Telegram Bot with Url InlineKeyboardButton for PHP

View Original

Solution:

<?php

    $token = '11345342......';
    $keyboard = json_encode([
        "inline_keyboard" => [
            [
                [
                    "text" => "Button 1",
                    "callback_data" => "1"
                ],
                [
                    "text" => "Button 2",
                    "callback_data" => "2"
                ]
            ]
        ]
    ]);

    $data = http_build_query([
        'text' => 'your message here',
        'chat_id' => '@channelname'
    ]);

    $url = "https://api.telegram.org/bot$token/sendMessage?{$data}&reply_markup={$keyboard}";
    $res = @file_get_contents($url);

enter image description here

Answer

Solution:

$token = "Your Token";
$chatID = "Your Chat iD";
$reply = "Message";


$keyboard = array(
    "inline_keyboard" => array(array(array("text" => "Your Buton Name", "url" => "Your Url")))
);

$keyboard = json_encode($keyboard, true);

$sendto = "https://api.telegram.org/bot$token/sendmessage?chat_id=".$chatID."&text=".$reply."&parse_mode=HTML&reply_markup=".$keyboard;

file_get_contents($sendto);

Source

See also:

  • php สร้าง Google ชีตจากบัญชีบริการ

  • php - Laravel 8.0 Installation Failed

  • javascript - How to include HTML data (tags) as value in "arrayToDataTable" of Google Pie Chart?

  • how to Grouping array in php

  • php - vender folder from my laravel project has more 1k error

© 2021
E-mail: contact@webdevask.com
Back to top