You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Malio/app/Utils/Telegram.php

70 lines
2.2 KiB
PHTML

9 years ago
<?php
namespace App\Utils;
use App\Services\Config;
use Exception;
use TelegramBot\Api\BotApi;
7 years ago
use Telegram\Bot\Api;
9 years ago
class Telegram
{
/**
7 years ago
* 发送消息
9 years ago
*/
public static function Send($messageText)
{
if (Config::get('enable_telegram') == true) {
7 years ago
// $bot = new BotApi(Config::get('telegram_token'));
// try {
// $bot->sendMessage(Config::get('telegram_chatid'), $messageText);
// } catch (Exception $e) {
// echo $e->getMessage();
// }
$bot = new Api(Config::get('telegram_token'));
$sendMessage = [
'chat_id' => Config::get('telegram_chatid'),
'text' => $messageText,
'parse_mode' => '',
'disable_web_page_preview' => false,
'reply_to_message_id' => null,
'reply_markup' => null
];
try {
7 years ago
$bot->sendMessage($sendMessage);
} catch (Exception $e) {
echo $e->getMessage();
}
9 years ago
}
}
9 years ago
public static function SendMarkdown($messageText)
{
if (Config::get('enable_telegram') == true) {
7 years ago
// $bot = new BotApi(Config::get('telegram_token'));
// try {
// $bot->sendMessage(Config::get('telegram_chatid'), $messageText, 'Markdown');
// } catch (Exception $e) {
// echo $e->getMessage();
// }
$bot = new Api(Config::get('telegram_token'));
$sendMessage = [
'chat_id' => Config::get('telegram_chatid'),
'text' => $messageText,
'parse_mode' => 'Markdown',
'disable_web_page_preview' => false,
'reply_to_message_id' => null,
'reply_markup' => null
];
try {
7 years ago
$bot->sendMessage($sendMessage);
} catch (Exception $e) {
echo $e->getMessage();
}
9 years ago
}
}
}