|
@@ -99,18 +99,41 @@ class Home extends Controller
|
|
|
return $this->success();
|
|
|
}
|
|
|
|
|
|
- public function setMenuButton()
|
|
|
+ public function setMenuButton($chatId)
|
|
|
{
|
|
|
- try {
|
|
|
- $telegram = new Api(config('services.telegram.token'));
|
|
|
- $res = $telegram->setMenuButton(['text' => '菜单', 'web_app' => ['url' => url('/api/onMessage')]]);
|
|
|
- } catch (TelegramSDKException $e) {
|
|
|
- return $this->error($e->getCode(), $e->getMessage());
|
|
|
- }
|
|
|
-
|
|
|
+ // try {
|
|
|
+ // $telegram = new Api(config('services.telegram.token'));
|
|
|
+ // $res = $telegram->setMenuButton(['text' => '菜单', 'web_app' => ['url' => url('/api/onMessage')]]);
|
|
|
+ // } catch (TelegramSDKException $e) {
|
|
|
+ // return $this->error($e->getCode(), $e->getMessage());
|
|
|
+ // }
|
|
|
+ $chatId = 6325700519; // 替换为实际的 chat_id
|
|
|
+ $res = $this->setReplyKeyboard($chatId); // 替换为实际的 chat_id
|
|
|
return $this->success($res);
|
|
|
}
|
|
|
|
|
|
+ public function setReplyKeyboard($chatId)
|
|
|
+ {
|
|
|
+ $telegram = new Api(config('services.telegram.token'));
|
|
|
+
|
|
|
+ $keyboard = [
|
|
|
+ ['菜单1', '菜单2'], // 第一排按钮
|
|
|
+ ['帮助', '设置'] // 第二排按钮
|
|
|
+ ];
|
|
|
+
|
|
|
+ $replyMarkup = [
|
|
|
+ 'keyboard' => $keyboard,
|
|
|
+ 'resize_keyboard' => true, // 自适应大小
|
|
|
+ 'one_time_keyboard' => false, // 保持显示,不会点击后收起
|
|
|
+ ];
|
|
|
+
|
|
|
+ $telegram->sendMessage([
|
|
|
+ 'chat_id' => $chatId,
|
|
|
+ 'text' => '请选择一个操作:',
|
|
|
+ 'reply_markup' => json_encode($replyMarkup),
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
public function getUpdates()
|
|
|
{
|
|
|
try {
|