如何使用Guzzle向电报机器人发送消息?

问题描述 投票:0回答:1

[当有人访问我的页面/tg/index.php时,我想使用php guzzle向我发送消息。我知道如何用php curl发送。但是我想用php guzzles发送。我可以使用php guzzles向自己发送消息吗?请与我分享代码

php telegram-bot guzzle
1个回答
0
投票

您可以使用GuzzleHttp\Client对象在Guzzle中发送请求。这是结合使用Guzzle documentationTelegram Bot API文档的示例:

$client = new GuzzleHttp\Client([ base_uri => "https://api.telegram.org/bot" . $token ]);
$client->request("POST", "sendMessage", [ 'body' => $messageParams ]);

((假设您在$token处具有bot令牌,并且$messageParams对象是表示您要发送的消息的JSON对象。

我建议您找出how you can make a request to the API specificallyhow you can achieve that with Guzzle

© www.soinside.com 2019 - 2024. All rights reserved.