Skip to content

Commit ef01c55

Browse files
committed
增加用户消息列表
1 parent 6ce33f9 commit ef01c55

File tree

4 files changed

+48
-7
lines changed

4 files changed

+48
-7
lines changed

app/Admin/Controllers/BotMessageController.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,36 @@ protected function grid()
4141
$username = $this->userData['username'] ?? '';
4242
return "<div style='padding:10px 10px'><p>UID: $uid</p><p>first name: $first_name</p><p>last name: $last_name</p><p>用户名: $username</p></div>";
4343
});
44+
45+
$grid->column('text')->display(function () {
46+
if (!empty($this->data['text'])){
47+
return $this->data['text'];
48+
}
49+
if (!empty($this->data['caption'])){
50+
return $this->data['caption'];
51+
}
52+
return '暂无信息';
53+
})->expand(function ($model) {
54+
$text = '暂无信息';
55+
if (!empty($this->data['text'])){
56+
$text = $this->data['text'];
57+
}
58+
if (!empty($this->data['caption'])){
59+
$text = $this->data['caption'];
60+
}
61+
$html="<div style='padding:10px 10px'><p>内容: {$text}</p></div>";
62+
//如果有图片
63+
// if (!empty($this->data['photo'])){
64+
// $html.="<div style='padding:10px 10px'><p>图片: </p>";
65+
// $imagesNum = count($this->data['photo'])-1;
66+
// $imageFileId = $this->data['photo'][$imagesNum]['file_id'];
67+
// $photo = get_file_url($imageFileId);
68+
// $html.="<img src='{$photo}' style='max-width: 100%;height: auto;'>";
69+
// $html.="</div>";
70+
// }
71+
return $html;
72+
});
73+
4474
$grid->column('created_at');
4575
$grid->column('updated_at')->sortable();
4676

app/Helpers/string.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,10 @@ function get_text_title($string)
9999
$limitedString = Str::limit($replaced);
100100
return Str::before($limitedString, PHP_EOL);
101101
}
102+
103+
function get_file_url($file_id)
104+
{
105+
$telegram = new \Telegram\Bot\Api(config('services.telegram.bot_token'));
106+
$file = $telegram->getFile(['file_id' => $file_id]);
107+
return 'https://api.telegram.org/file/bot'.config('services.telegram.bot_token').'/'.$file_id;
108+
}

app/Http/Controllers/Bots/TestController.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@ public function pa()
1616
{
1717
$telegram = new Api(env('TELEGRAM_BOT_TOKEN'));
1818

19-
$text="稿件消息<a href='https://t.me/123'>123</a>";
20-
21-
dd($telegram->sendMessage([
22-
'chat_id' => '6247385123',
23-
'text' => $text,
24-
'parse_mode' => 'HTML',
25-
]));
19+
$file=$telegram->getFile(['file_id'=>'AgACAgEAAxkBAAIB2GYPabtpIuMVtmNIYreBYbEagoq7AALHqzEbvsSARJrVHae73dkSAQADAgADcwADNAQ']);
20+
dd($file);
21+
22+
// $text="稿件消息<a href='https://t.me/123'>123</a>";
23+
//
24+
// dd($telegram->sendMessage([
25+
// 'chat_id' => '6247385123',
26+
// 'text' => $text,
27+
// 'parse_mode' => 'HTML',
28+
// ]));
2629
}
2730

2831

lang/zh_CN/bot-message.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
'userData' => '用户信息',
1414
'data' => '消息整体',
1515
'user_name'=> '用户名称',
16+
'text' => '消息内容',
1617
],
1718
'options' => [
1819
],

0 commit comments

Comments
 (0)