标签: telegram-bot

Telegram BOT - 如何添加图标?

如何向电报机器人添加图标?

示例命令:

/统计数据

响应代码:

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)

javascript telegram-bot

2
推荐指数
1
解决办法
6168
查看次数

如何使用 gitignore 隐藏机器人 Telegram 令牌?

在公共领域的 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)

github gitignore python-3.x telegram-bot

2
推荐指数
1
解决办法
2707
查看次数

Telegram 不再接受通配符证书。在 pythonanywhere 中出现错误

当我在 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 pythonanywhere telegram telegram-bot telepot

2
推荐指数
1
解决办法
768
查看次数

我正在用 python 编写一个电报机器人

我想通过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 telegram telegram-bot

2
推荐指数
1
解决办法
5133
查看次数

在服务器上持久运行Python脚本

我有一个 python 机器人,托管在数字海洋上。现在为了持续运行它,我正在使用虚拟终端屏幕,我发现这种方式还很不稳定。

如何安排我的机器人脚本永远运行并在崩溃时重新运行?还有我如何安排其他一些 python 脚本每小时运行一次?

python ubuntu telegram-bot

2
推荐指数
1
解决办法
2974
查看次数

Telethon 在按钮后写消息/开始聊天 - 机器人在/开始之前发送消息

我正在尝试编写一个带有 telethon for telegram 的访问机器人。

  1. 用户已添加到群组或通过邀请链接加入。
  2. 受到限制,必须按下按钮。
  3. 机器人会编写一条简单的验证码消息,例如“1+2=?”
  4. 如果是对的,这个人就不受限制,如果错了,就会被踢出去……

一切都工作得很好,但是:
如果新加入的用户没有先写“/start”,则用户不会从机器人收到消息。

该人是否有可能收到该消息?

我读过在某个地方不可能做到这一点,但是外面有机器人怎么办?

python telegram telegram-bot telethon

2
推荐指数
1
解决办法
1887
查看次数

Telegram Bot sendDocument(托管服务器上的 php)

我有一个 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)

php post curl file-upload telegram-bot

2
推荐指数
1
解决办法
5673
查看次数

导入错误:无法从“电报”导入名称“机器人”

我正在尝试向 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)

python heroku python-3.x telegram telegram-bot

2
推荐指数
1
解决办法
2万
查看次数

从 Telegram 的机器人 API 获取投票结果和用户选择

我想知道是否有办法使用机器人 API 查找用户对非匿名投票的回复。我可以获得投票数,但我想知道特定用户的实际选择。

python telegram python-telegram-bot telegram-bot

2
推荐指数
1
解决办法
7686
查看次数

如何使用 Native API 发送 Telegram Bold 消息?

我想使用本机 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)

python telegram-bot

2
推荐指数
1
解决办法
5006
查看次数