标签: telepot

如何在 Telepot Telegram bot 中加粗文本?

我试过这个

elif command == 'bold':
    telegram_bot.sendMessage (chat_id, str("*bold*"), reply_markup=markup)
Run Code Online (Sandbox Code Playgroud)

但它是回复*bold*而不是粗体

python python-3.x telegram-bot telepot

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

错误请求:查询太旧,响应超时或查询 ID 无效

我已经在电报机器人上工作了很长时间,但是当我按下内联键以接收弹出窗口时:

bot.answerCallbackQuery (aalex_id, text = 'Notification at top of screen)
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

TelegramError: (u'Bad Request: query is too old and response timeout expired or query ID is invalid ', 400
Run Code Online (Sandbox Code Playgroud)

查询 id 是正确的,而且不是那么旧,哈哈……我不知道该怎么办:c

python telepot

8
推荐指数
1
解决办法
2044
查看次数

如何在电报机器人上发送照片

我只是实现了一个简单的机器人,该机器人应该将一些照片和视频发送给我chat_id。好吧,我正在使用python,这是脚本

import sys
import time
import random
import datetime
import telepot

def handle(msg):
    chat_id = msg['chat']['id']
    command = msg['text']

    print 'Got command: %s' % command

    if command == 'command1':
        bot.sendMessage(chat_id, *******)
    elif command == 'command2':
        bot.sendMessage(chat_id, ******)
    elif command == 'photo':
        bot.sendPhoto(...)

bot = telepot.Bot('*** INSERT TOKEN ***')
bot.message_loop(handle)
print 'I am listening ...'

while 1:
    time.sleep(10)
Run Code Online (Sandbox Code Playgroud)

在这一行中,bot.sendphoto我将插入chat_id图像的路径和,但是什么也没有发生。

我哪里错了?

谢谢

python telegram-bot telepot

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

DelegatorBot如何在TelePot中正常工作?

我正在尝试Telepot通过查看counter.py此处提供的示例来研究python库:https://github.com/nickoala/telepot/blob/master/examples/chat/counter.py.
我发现有点难以理解DelegatorBot课程的实际运作方式.

这是我认为到目前为止我所理解的:

1.

我看到最初定义了这个类(派生自"ChatHandler"类):

class MessageCounter(telepot.helper.ChatHandler):

    def __init__(self, *args, **kwargs):
        super(MessageCounter, self).__init__(*args, **kwargs)
        self._count = 0

    def on_chat_message(self, msg):
        self._count += 1
        self.sender.sendMessage(self._count)
Run Code Online (Sandbox Code Playgroud)

2.

然后通过实例化类来创建机器人DelegatorBot:

bot = telepot.DelegatorBot(TOKEN, [
    pave_event_space()(
        per_chat_id(), create_open, MessageCounter, timeout=10
    ),
])
Run Code Online (Sandbox Code Playgroud)

3.

我知道DelegatorBot创建了一个新实例并将其放入变量中bot.第一个参数是电报验证此机器人所需的令牌,第二个参数是包含我不理解的内容的列表.

我的意思是这部分:

pave_event_space()(
    per_chat_id(), create_open, MessageCounter, timeout=10
)
Run Code Online (Sandbox Code Playgroud)

然后我的问题是......

pave_event_space()称为一个方法,它返回到另一种方法的参考?然后使用参数调用此返回的方法(per_chat_id(), create_open, MessageCounter, timeout=10)

python telegram telepot

4
推荐指数
1
解决办法
1412
查看次数

如何在 bot.sendMessage() 中发送超链接

我的机器人发送链接。所以我想包含一个像你可以用 HTML 做的超链接,例如-a href="google.com" Google /a显示一个名为“谷歌”的可点击文本,我该怎么做bot.sendMessage()?并且如果您也有任何发送粗体消息的想法..

python telegram-bot telepot

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

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
查看次数

电报机器人 - 找不到聊天

我对电报机器人完全陌生。我想bot.send_message()在以下代码中执行 a (如代码中所述),但不能这样做。请帮忙。

!pip install python-telegram-bot --upgrade
import telegram
bot = telegram.Bot(token='**************')
bot.send_message(chat_id='******', text="I'm sorry Dave I'm afraid I can't do that.")
Run Code Online (Sandbox Code Playgroud)

它错误为:

1 bot.send_message('mardepbot',"I'm sorry Dave I'm afraid I can't do that.")

/usr/local/lib/python3.6/dist-packages/telegram/bot.py in decorator(self, *args, **kwargs)
     63     def decorator(self, *args, **kwargs):
     64         logger.debug('Entering: %s', func.__name__)
---> 65         result = func(self, *args, **kwargs)
     66         logger.debug(result)
     67         logger.debug('Exiting: %s', func.__name__)

/usr/local/lib/python3.6/dist-packages/telegram/bot.py in decorator(self, *args, **kwargs)
     88                 data['reply_markup'] = reply_markup
     89 
---> 90         result = self._request.post(url, data, timeout=kwargs.get('timeout'))
     91 …
Run Code Online (Sandbox Code Playgroud)

telepot

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

踢 TELEPOT 时机器人不断显示相同的错误

我创建了一个电报机器人,它只打印我发送的消息,一切正常,直到我阻止它或从组中添加/踢它,当我这样做时,机器人不断显示此错误:1

这是代码:

import telepot
from telepot.loop import MessageLoop
from pprint import pprint
import time

TOKEN="..."

def handler(msg):
    content, chat, id=telepot.glance(msg)
    pprint(msg)

bot=telepot.Bot(TOKEN)
bot.message_loop(handler)

while True:
    time.sleep(10)
Run Code Online (Sandbox Code Playgroud)

我也尝试过使用该getUpdates功能,它会不断打印所有消息,甚至是旧的已删除消息。我认为问题是由“存储”消息引起的,但我不知道如何解决它。

我在用着:

  • 遥控器版本12.7
  • 蟒蛇3.9.0

python telegram-bot telepot

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