amohamed / telegram-atm
这是一个自定义的Telegram服务机器人
dev-main
2023-07-09 19:34 UTC
Requires
- php: >=7.2
- illuminate/support: >=7.2
This package is auto-updated.
Last update: 2024-09-09 21:46:54 UTC
README
这是一个用于与Telegram API交互的自定义Laravel包。
安装
使用composer安装此包
composer require amohamed/telegram-atm:dev-main
配置
使用以下命令发布包配置文件:
php artisan vendor:publish --provider="Amohamed\TelegramAtm\TelegramAtmServiceProvider" --tag=migrations
然后,您可以通过修改位于 config/telegramatm.php
的已发布配置文件来设置您的Telegram机器人的详细信息。
使用方法
在您的服务或控制器中注入 Amohamed\TelegramAtm\TelegramAtmService
use Amohamed\TelegramAtm\TelegramAtmService; class MyController extends Controller { protected $telegramAtmService; public function __construct(TelegramAtmService $telegramAtmService) { $this->telegramAtmService = $telegramAtmService; } public function someMethod() { // Use the telegramAtmService instance } }
可用方法
以下是您可以使用的可用方法
getApiUrl($method)
此方法返回给定方法的Telegram API URL。
$method
(string): Telegram API方法。
sendRequest($url, $params = [])
此方法向Telegram API发送请求。
$url
(string): Telegram API URL。$params
(array): 请求参数。
getMe()
此方法返回有关机器人的信息。
sendMessage($chat_id, $text, $parse_mode = null, $disable_web_page_preview = null, $disable_notification = null, $reply_to_message_id = null, $reply_markup = null)
此方法向聊天发送文本消息。
$chat_id
(int|string): 聊天ID。$text
(string): 消息文本。$parse_mode
(string|null): 消息文本的解析模式。$disable_web_page_preview
(bool|null): 是否禁用网页预览。$disable_notification
(bool|null): 是否禁用通知。$reply_to_message_id
(int|null): 被回复消息的ID。$reply_markup
(array|null): 回复标记。
forwardMessage($chat_id, $from_chat_id, $message_id, $disable_notification = null)
此方法将一条消息从一个聊天转发到另一个聊天。
$chat_id
(int|string): 聊天ID。$from_chat_id
(int|string): 源聊天的ID。$message_id
(int): 消息ID。$disable_notification
(bool|null): 是否禁用通知。
sendPhoto($chat_id, $photo, $caption = null, $parse_mode = null, $disable_notification = null, $reply_to_message_id = null, $reply_markup = null)
此方法向聊天发送照片。
$chat_id
(int|string): 聊天ID。$photo
(string): 照片文件路径或URL。$caption
(string|null): 照片说明。$parse_mode
(string|null): 照片说明的解析模式。$disable_notification
(bool|null): 是否禁用通知。$reply_to_message_id
(int|null): 被回复消息的ID。$reply_markup
(array|null): 回复标记。
sendAudio($chat_id, $audio, $caption = null, $parse_mode = null, $duration = null, $performer = null, $title = null, $disable_notification = null, $reply_to_message_id = null, $reply_markup = null)
此方法向聊天发送音频文件。
$chat_id
(int|string): 聊天ID。$audio
(string): 音频文件路径或URL。$caption
(string|null): 音频说明。$parse_mode
(string|null): 音频说明的解析模式。$duration
(int|null): 音频文件时长。$performer
(string|null): 音频文件表演者。$title
(string|null): 音频文件标题。$disable_notification
(bool|null): 是否禁用通知。$reply_to_message_id
(int|null): 被回复消息的ID。$reply_markup
(array|null): 回复标记。
getUserSession($chat_id)
此方法返回给定聊天ID的用户会话数据。
$chat_id
(int|string): 聊天ID。
getCommand($text)
此方法从给定文本中返回命令。
$text
(string): 文本。
getCommandParams($text)
此方法从给定文本中返回命令参数。
$text
(string): 文本。
deleteUserSession($chatId)
此方法删除给定聊天ID的用户会话数据。
$chatId
(int|string): 聊天ID。
许可证
此软件包是开源软件,根据MIT许可证授权。