我开始编程电报机器人,我遇到了问题.当我发送/启动命令时,它向我发送一条欢迎消息(正如我编程的那样),但它不发送一次!它像循环一样无休止地发送它!这是来源:
<?php
define('API_KEY','<token>');
function makereq($method,$datas=[])
{
$url = "https://api.telegram.org/bot".API_KEY."/".$method;
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_POSTFIELDS,http_build_query($datas));
$res = curl_exec($ch);
if(curl_error($ch)){
var_dump(curl_error($ch));
}else{
return json_decode($res);
}
}
$website = "https://api.telegram.org/bot".API_KEY;
$update = json_decode(file_get_contents('php://input'));
$chat_id = $update->message->chat->id;
$message_id = $update->message->message_id;
$from_id = $update->message->from->id;
$name = $update->message->from->first_name;
$username = $update->message->from->username;
$textmessage = isset($update->message->text)?$update->message->text:'';
$reply = $update->message->reply_to_message->forward_from->id;
$stickerid = $update->message->reply_to_message->sticker->file_id;
$messageEntity = $update->messageentity->type;
function SendMessage($ChatId, $TextMsg)
{
makereq('sendMessage',[
'chat_id'=>$ChatId,
'text'=>$TextMsg,
'parse_mode'=>"MarkDown"]
);
}
if($textmessage == '/start')
{
SendMessage($chat_id,'<welcome message>');
}
?>
Run Code Online (Sandbox Code Playgroud) 我希望通过php获取api的电报频道更新(帖子)!(我不是渠道管理员)
我不确定我能用机器人这样做吗?
如果不可能用电报api怎么办呢?
我正在尝试将机器人连接到我的Web主机并访问数据库并与PHP交互.但是我经常搜索并发现我需要拥有SSL证书.有没有办法在没有SSl的情况下设置机器人?
我在 Telegram 中有一个机器人,我可以通过哪个查询获取组或频道中所有消息的列表?
据我了解,请求如下:
https://api.telegram.org/bot_token/getUpdates?chat_id=@chat
Run Code Online (Sandbox Code Playgroud)
让我只获取更新,但如何仅使用 Bot API 获取完整的帖子列表?
如何正确发送此文本:
$parameters['text'] = 'you must see [example](example.com) or contact with @exmaple_com';
Run Code Online (Sandbox Code Playgroud)
如果我不使用“ Markdown”,则电报不会显示上述链接;如果我使用“ Markdown”,则电报将无法处理下划线。
我必须在PHP程序,由于公司需要......但我与PHP的首次工作......这是第一次,我用电报机器人的工作:"(在某种程度上,之前,当我跑的命令/start和doWork一切正常......
但现在我必须修改机器人,所有命令都隐藏在某个电报按钮后面...这里我是如何编辑我的php页面的:
if(strpos($text, "/start") === 0)
{
$response = "Ciao $firstname, benvenuto!";
$keyboard = [
'inline_keyboard' => [
[
['text' => 'forward me to groups']
]
]
];
$encodedKeyboard = json_encode($keyboard);
$parameters =
array(
'chat_id' => $chatId,
'text' => $response,
'reply_markup' => $encodedKeyboard
);
$parameters["method"] = "sendMessage";
echo json_encode($parameters);
}
Run Code Online (Sandbox Code Playgroud)
有了BotFather,我也运行了命令/setinline......
所以我想我正在研究我的parameters阵列..有人能帮助我吗?
Ps.:(如果任何人都可以建议我也是我工作的IDE请...我现在使用notepad ++)
谢谢你们
$media[]=[\'\xe2\xac\x85\xef\xb8\x8f\',\'\'];
这是我的电报机器人按钮。
\n\n它太大了,我不喜欢这个。
\n\n如何小型化电报按钮?
\n\n我想我需要这个:resize_keyboard
但我不知道如何使用它来缩小按钮。
\n\n这是我的功能请求:
\n\nvar_dump(\n makeHTTPRequest(\'sendMessage\',[\n \'chat_id\'=>userid,\n \'text\'=>"Text",\n \'reply_markup\'=>json_encode(array(\'keyboard\'=> [[\'\xe2\xac\x85\xef\xb8\x8f\',\'Button\',\'\']]))\n ])\n);\nRun Code Online (Sandbox Code Playgroud)\n\n我怎样才能缩小这个按钮?
\n我正在制作一个基本的控制面板,用于使用PHP管理Bot。
基本上,我想显示向机器人发送消息的用户的个人资料图片/头像。
但是,用户对象没有photo_id,那么有没有办法获取用户的头像?
php telegram python-telegram-bot telegram-bot php-telegram-bot
我正在开发一个 Telegram 机器人,并希望使用ngrok从webhook接收消息。
设置 webhook 有效。当我将可公开访问的域设置为 URL 时,我实际上收到了预期的消息。现在,当我知道代码正在运行时,我想将消息从 ngrok 服务器传输到本地虚拟机。
$ ngrok http telegrambot.sandbox.loc:80
ngrok by @inconshreveable (Ctrl+C to quit)
Session Status online
Session Expires 7 hours, 59 minutes
Version 2.2.8
Region United States (us)
Web Interface http://127.0.0.1:4040
Forwarding http://0955b8f3.ngrok.io -> telegrambot.sandbox.loc:80
Forwarding https://0955b8f3.ngrok.io -> telegrambot.sandbox.loc:80
Connections ttl opn rt1 rt5 p50 p90
0 0 0.00 0.00 0.00 0.00
Run Code Online (Sandbox Code Playgroud)
出色地。现在我设置了 webhook 并得到了类似的响应
{
"ok":true,
"result":{
"url":"https://a200f5f7.ngrok.io",
"has_custom_certificate":false,
"pending_update_count":0,
"max_connections":40
}
}
Run Code Online (Sandbox Code Playgroud)
ngrok 的 CLI 输出:
HTTP Requests …Run Code Online (Sandbox Code Playgroud) telegram ngrok telegram-bot php-telegram-bot telegram-webhook
我正在制作一个数据库,其中我的算法只接受来自电报 ID 长度为 9 的用户的查询。
user_id: 123456789;
length = user_id.length;
display(length);
OUTPUT: 9
Run Code Online (Sandbox Code Playgroud)
是否存在长度小于 9 的电报用户 ID?
任何人都可以提出建议,以便我也可以将我的算法更新为该 ID 的长度。
telegram python-telegram-bot telegram-bot lua-telegram-bot php-telegram-bot