Contacts the various API's endpoints
Values inside $content:
*
\param $content the request parameters as array
\return the JSON Telegram's reply
Values inside $content:
*
Parameters | Type | Required | Description |
chat_id | Integer | Yes | Unique identifier for the message recipient — User or GroupChat id |
text | String | Yes | Text of the message to be sent |
parse_mode | String | Optional | Send Markdown, if you want Telegram apps to show bold, italic and inline URLs in your bot's message. For the moment, only Telegram for Android supports this. |
disable_web_page_preview | Boolean | Optional | Disables link previews for links in this message |
reply_to_message_id | Integer | Optional | If the message is a reply, ID of the original message |
reply_markup | ReplyKeyboardMarkup or ReplyKeyboardHide or ForceReply | Optional | Additional interface options. A JSON-serialized object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user. |
public sendMessage ( array $content ) | ||
$content | array |
public function process($data) { if (isset($data['message']) && isset($data['message']['text'])) { switch ($data['message']['text']) { case '/start': //выодим сообщение, что нужно написать ключ return $this->telegram->sendMessage('Введите сгенерированный код', $data['message']['chat']['id']); break; case '/stop': if ($this->deleteChatID($data['message']['chat']['id'])) { return $this->telegram->sendMessage('Вы отключили функцию уведомления', $data['message']['chat']['id']); } break; case '/help': return $this->telegram->sendMessage("Для подключения уведомлений введите сгенерированный код \n Для отключения уведомлений введите команду /stop ", $data['message']['chat']['id']); break; default: if ($this->alreadyConnected($data)) { return false; } if (preg_match('#^\\d+$#', $data['message']['text'])) { //число return $this->connectUserByCode($data['message']['text'], $data['message']['chat']['id']); } else { return $this->telegram->sendMessage('not int', $data['message']['chat']['id']); } } } return 'no_cmd'; }
// 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") { $reply = "Check me on GitHub: https://github.com/Eleirbag89/TelegramBotPHP"; $content = array('chat_id' => $chat_id, 'text' => $reply);
ob_start(); header("Content-Type: application/json"); if (!file_exists("config.php")) { die("Please copy config.php-example to config.php and insert your API-Key into it."); } require_once "config.php"; require_once "Telegram.class.php"; if (API_KEY == "") { die("Please define your API-Key."); } global $tg; $tg = new Telegram(API_KEY); $availableCommands = ["help", "shorturl", "weather", "bot", "encode", "dns", "mac", "ping", "stats", "traceroute", "permission"]; $commandAlias = ["man" => "help", "l" => "shorturl", "dig" => "dns", "trace" => "traceroute"]; if ($tg->getText() == "debuginfo") { $tg->sendMessage(file_get_contents('php://input')); } // Request from Telegram-Webhooks if (isset($_GET["t"]) && $_GET["t"] == "webhook") { // Check if message was a command if (strpos($tg->getText(), "/") === 0) { $command = strtolower(ltrim($tg->getCommand()["command"], "/")); if (isset($commandAlias[$command])) { $command = $commandAlias[$command]; } if (in_array($command, $availableCommands)) { include_once "commands/" . $command . ".php"; } } else { if ($tg->getChatType() == "private") { // Special commands/action on private messages?
private function sendTelegramMessage($transaction) { $response = \Telegram::sendMessage(['chat_id' => env('CHAT_ID'), 'text' => $this->createMessage($transaction)]); }