如何向电报机器人添加图标?
示例命令:
/统计数据
响应代码:
var response = '';
response += '*Pool*\n';
response += 'Hashrate: ' + poolHashrate + '\n';
response += 'Connected Miners: ' + poolMiners + '\n';
response += 'Active Workers: ' + poolWorkers + '\n';
response += 'Blocks Found: ' + poolBlocks + '\n';
response += 'Last Block: ' + poolLastBlock + '\n';
response += 'Current Effort: ' + currentEffort + '\n';
response += '\n';
response += '*Network*\n';
response += 'Hashrate: ' + networkHashrate + '\n';
response += …
Run Code Online (Sandbox Code Playgroud) 在公共领域的 GitHub 上是我的电报机器人的代码,我的令牌在哪里。我想隐藏它,我该怎么办?我知道这应该用 gitignore 来完成
import telebot
import time
TOKEN = "872521057:AAF2Kx4Y3WC-cs................"
bot = telebot.TeleBot(TOKEN)
@bot.message_handler(commands=['start', 'help'])
def send_welcome(message):
bot.reply_to(message, "Hello")
@bot.message_handler(func=lambda m: True)
def echo_all(message):
bot.reply_to(message, message.text)
bot.polling(none_stop=True)
Run Code Online (Sandbox Code Playgroud) 当我在 pythonanywhere 上部署我的机器人时,我无法向我的机器人发送消息。由于 telegram 不再支持通配符证书,如博客文章的官方 pythonanywhere 博客链接中所述,出现无法连接到服务器的错误。如果有人知道此问题的解决方案,请帮助我
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='api.telegram.org', port=443): Max retries exceeded with url: /bottokenvalue/sendMessage (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f094debf050>: Failed to establish a new connection: [Errno 101] Network is unreachable'))
2020-01-17 21:58:04,377: Retrying (Retry(total=2, connect=None, read=None, redirect=0, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f094da4c610>: Failed to establish a new connection: [Errno 101] Network is unreachable')': /bottoken/sendMessage
2020-01-17 21:58:05,377: Retrying (Retry(total=1, connect=None, read=None, redirect=0, status=None)) after connection broken …
Run Code Online (Sandbox Code Playgroud) 我想通过Python编写一个电报机器人,但它不起作用。
import telebot
bot = telebot.TeleBot("my_token")
@bot.message_handler(content_types=['text'])
def sending(message):
bot.send_message(message.chat.id, message.text)
# RUN
bot.polling(non_stop=True)
Run Code Online (Sandbox Code Playgroud)
返回给我以下问题。
AttributeError:“TeleBot”对象没有属性“message_handler”
我有一个 python 机器人,托管在数字海洋上。现在为了持续运行它,我正在使用虚拟终端屏幕,我发现这种方式还很不稳定。
如何安排我的机器人脚本永远运行并在崩溃时重新运行?还有我如何安排其他一些 python 脚本每小时运行一次?
我正在尝试编写一个带有 telethon for telegram 的访问机器人。
一切都工作得很好,但是:
如果新加入的用户没有先写“/start”,则用户不会从机器人收到消息。
该人是否有可能收到该消息?
我读过在某个地方不可能做到这一点,但是外面有机器人怎么办?
我有一个 Telegram 机器人,在第三方托管服务器上设置了 webhook。我可以使用任何URL 查询字符串,并且它们工作得很好。
现在我试图让我的机器人发送一个文本文件。如果我理解正确,我需要使用 发出 POST 请求multipart/form-data
,并且我正在努力使其在托管服务器上工作。
$url = "https://api.telegram.org/bot<myToken>/sendDocument?chat_id=$<myId>";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$post = array( 'document' => '@'.realpath('data.txt'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$headers = array();
$headers[] = 'Content-Type: multipart/form-data';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
//DEBUGGING-------------------------------
$info = curl_getinfo($ch);
$buffer = "";
foreach ($info as $key => $value) {
$buffer .= "$key => $value\n";
}
sendMessage($buffer, $<myId>);
//----------------------------------------
$result = curl_exec($ch);
//DEBUGGING-------------------------------
sendMessage($result, $<myId>);
//----------------------------------------
curl_close($ch); …
Run Code Online (Sandbox Code Playgroud) 我正在尝试向 Heroku 部署一个简单的呼叫和响应机器人,但我不断收到相同的错误,并且不知道如何修复它。我发现该程序可以在我的个人计算机上运行,但当我将其部署到 Heroku 时却无法运行。我觉得这与我的导入声明有关:
import random
from telegram.ext import Updater
from telegram.ext import CommandHandler
from telegram.ext import MessageHandler
from telegram.ext import Filters
from telegram.ext import messagequeue as mq
from telegram.utils.request import Request
import logging
import os
Run Code Online (Sandbox Code Playgroud)
在推送到 heroku 并运行它后,我收到这些错误:
2021-03-27T08:25:40.562359+00:00 heroku[web.1]: Starting process with command `python3 bog_bot.py`
2021-03-27T08:25:43.167956+00:00 heroku[web.1]: Process exited with status 1
2021-03-27T08:25:43.257029+00:00 heroku[web.1]: State changed from starting to crashed
2021-03-27T08:25:43.102105+00:00 app[web.1]: Traceback (most recent call last):
2021-03-27T08:25:43.102177+00:00 app[web.1]: File "/app/bog_bot.py", line 2, in <module>
2021-03-27T08:25:43.102489+00:00 app[web.1]: …
Run Code Online (Sandbox Code Playgroud) 我想知道是否有办法使用机器人 API 查找用户对非匿名投票的回复。我可以获得投票数,但我想知道特定用户的实际选择。
我想使用本机 Python 请求发送Telegram消息,以便在使用BOLD时收到“名字” 。我尝试过 HTML 和 Markdown 语法,但没有显示。
import json
import requests
# Telegram bot configurations
TELE_TOKEN='TOKEN'
URL = "https://api.telegram.org/bot{}/".format(TELE_TOKEN)
def send_message(text, chat_id):
url = URL + "sendMessage?text={}&chat_id={}".format(text, chat_id)
requests.get(url)
# AWS Lambda handler
def lambda_handler(event, context):
message = json.loads(event['body'])
chat_id = message['message']['chat']['id']
first_name = message['message']['chat']['first_name']
text = message['message']['text']
# How can the first name be in BOLD?
reply = "Hello " + first_name + "! You have said:" + text
send_message(reply, chat_id)
return {
'statusCode': 200 …
Run Code Online (Sandbox Code Playgroud) telegram-bot ×10
python ×7
telegram ×5
python-3.x ×2
curl ×1
file-upload ×1
github ×1
gitignore ×1
heroku ×1
javascript ×1
php ×1
post ×1
telepot ×1
telethon ×1
ubuntu ×1