phpjavascript-电报telegram技巧分享

telegram机器人不回复消息

加速

PHP

中的

Telegram

Bot API_course


2016-08-01

<div class=”post-text” itemprop=”text”> <p>I have used

PHP

in order to write a

Telegram

bot that uses <code>webhook</code> which means that the

PHP

file is called for each update. I have used curl in order to post JSON to <a href=”https://api.

telegram

.org” rel=”nofollow”>https://api.

telegram

.org</a>. When I send a message in my

PHP

file, it responds in around <strong>1 second</strong>. I think because it does not reuse the curl connection. the connection closes after the

PHP

file finishes.</p> <p>I have also written a Java application that calls <code>getUpdate</code> method every 5 seconds. It responds in around <strong>500 milliseconds</strong> because it reuses the connection.</p> <p>How can I speed up my

PHP

bot just like my Java application? Is there any way to reuse the connection even when the

PHP

file is finished and another

PHP

file is run?</p> <p>Here is my

PHP

code:</p> <pre><code>function Post($method, $data) { $url = “https://api.

telegram

.org/bot”.$authenticationToken.”/”.$method; $curl = curl_init(); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, “POST”); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($curl, CURLOPT_HTTPHEADER, array(“Content-type: application/json”)); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_ENCODING, ”); $resultJSON = curl_exec($curl); curl_close($curl); $result = json_decode($resultJSON,true); if(!$result[“ok”]) LogF($resultJSON); return $result; } </code></pre> <p>P.S: the ping time of the URL is around <strong>200 milliseconds</strong>.</p> </div>

使用节点js的电报漫游!器未在组中回答。当我在群组中发短信时,它会在我的个人聊天中立刻回答我。

-这个小组是一个超级小组

-该机器人是管理员

-隐私设置被禁用

仍旧有这个问题。我该怎么做??


const TelegramBot = require('node-telegram-bot-api'); const token = 'my bot_token here'; const bot = new TelegramBot(token, {polling: true}); bot.on('message', (msg) => { var Hi = "hi"; if (msg.text.toString().toLowerCase().indexOf(Hi) === 0) { bot.sendMessage(msg.from.id, "Hello " + msg.from.first_name); } });

您应该使用chat.id而不是user.id:


const TelegramBot = require('node-telegram-bot-api'); const token = 'my bot_token here'; const bot = new TelegramBot(token, {polling: true}); bot.on('message', (msg) => { var Hi = "hi"; if (msg.text.toString().toLowerCase().indexOf(Hi) === 0) { bot.sendMessage(msg.chat.id, "Hello " + msg.from.first_name); } });

Join GitHub today

GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.

Sign up

You can’t perform that action at this time.


You signed in with another tab or window.
Reload
to refresh your session.


You signed out in another tab or window.
Reload
to refresh your session.

本文网址:

http://www.1cm8858.com/d/20208510327_5076_811308703/home

Ten articles before and after

密码的近义词解释-电报telegram技巧分享

莫尔斯摩尔斯电码练习器发电报短波电台cw自动电键电子键无线电谍战片里绝密情报都是电报员收发的-电报telegram技巧分享

应用文体:书信电报、电报挂号远去的词汇-电报telegram技巧分享

看完了你还敢说你不懂西联汇款吗?日军截获电报-电报telegram技巧分享

解除编译自己的iOS版Telegram-电报telegram技巧分享

「史海」失之毫厘、差之千里抗战破译日军密码四大英杰:预知日本偷袭珍珠港-电报telegram技巧分享

nep.电报群优质汇总(同城-电报telegram技巧分享

最佳电报渠道及其使用方法如何TelegramBotAPI获取频道用户列表-电报telegram技巧分享

终于知道yy是什么意思了幽冥这个词是-电报telegram技巧分享

【qc小组传真电报保密宣传-电报telegram技巧分享