kodeops / laravel-telegram-wrapper
Laravel Telegram API 包装器。
1.0.19
2023-08-16 11:44 UTC
Requires
- php: ^7|^8
- laravel/framework: ^8|^9|^10
README
_ _ _____ ______ _______ _____ _____ _______
|____/ | | | \ |______ | | |_____] |______
| \_ |_____| |_____/ |______ |_____| | ______|
Laravel Telegram API 包装器
此包是 Telegram API 的包装器。
安装 composer 依赖
$ composer require kodeops/laravel-telegram-wrapper
设置日志记录
在 logging.php
配置文件中添加一个新的 channel
'telegram' => [
'driver' => 'single',
'path' => storage_path('logs/telegram.log'),
'level' => 'info',
],
添加环境设置
这些将默认使用,此外,您可以在实例化对象时传递凭证。
TELEGRAM_DEBUG=false
TELEGRAM_BOT_TOKEN=<token>
TELEGRAM_CHAT_ID=<chat_id>
用法
发送新消息
use kodeops\LaravelTelegramWrapper\Telegram;
return (new Telegram())
->withMarkdown($markdown)
->sendMessage();
您还可以在实例化对象时指定凭证(bot_token
和 chat_id
)。
use kodeops\LaravelTelegramWrapper\Telegram;
return (new Telegram($bot_token))
->chat($chat_id)
->withMarkdownImage($image)
->withKeyboard($keyboard)
->withMarkdown($markdown)
->sendMessage();
这将产生一条顶部带有图片的消息,并使用图片作为通知高亮。
use kodeops\LaravelTelegramWrapper\Telegram;
$keyboard = [
'inline_keyboard' => [
[
[
'text' => 'Text Button',
'url' => 'https://tannhauser-gate.xyz',
],
]
]
];
$markdown = 'A simple *markdown* text';
$image = 'https://iibusiness.s3.eu-central-1.amazonaws.com/tannhauser/favicon.jpg';
return (new Telegram())
->withKeyboard($keyboard)
->withMarkdownCaption($markdown)
->sendPhoto($image);
发送消息的选项
-
disableWebPagePreview()
:禁用此消息中链接的预览 -
withKeyboard($keyboard)
:设置消息的键盘 -
withMarkdown($markdown)
:设置 markdown 文本 -
withMarkdownImage($image)
:使用 markdown 设置消息的图片 -
withMarkdownCaption($markdown)
:将 markdown 文本设置为标题(与sendPhoto($image)
结合使用很有用)
实用工具
-
setMyCommands($commands)
:设置机器人命令 -
setWebhook($url)
:设置 webhooks URL 关于 webhooks 的更多信息 -
getWebhookInfo()
:获取 webhooks 信息
其他功能
通常,您可以使用 setParam($key, $value)
方法向请求添加参数。