标签: telegram-bot

Node Telegram bot api,在用户之间进行链接对话

我已经开始使用这个模块为电报编写机器人逻辑

我可以像这样创建简单的问答逻辑:

bot.onText(/\/start/, function(msg, match){
  bot.sendMessage(msg.chat.id, "Hello this is great bot");
});
Run Code Online (Sandbox Code Playgroud)

当用户输入时,/start他将收到此消息.

我想创建像bot和用户之间的链式对话.就像用户类型/buy机器人会显示购买选项一样,在用户输入他想要购买的东西之后,机器人将显示所选产品的类型等等.

如何在用户和机器人之间创建链式对话?如何使机器人记住以前选择的命令并在时间重置它们?我需要保留在自己的数据库中才能这样做吗?

javascript node.js telegram telegram-bot

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

我应该如何在电报 python bot 中使用 parse_mode='HTML'?

我正在尝试使用 Telegram API 的send_photo()方法在带有机器人的频道中发送消息。它需要一个标题参数(类型String),但我无法通过parse_mode='HTML'参数格式化它...

如果我使用这样的东西:

send_photo(chat_id, photo, caption="<b>Some text</b>", parse_mode='HTML') 
Run Code Online (Sandbox Code Playgroud)

它发送消息但没有任何格式。有人知道为什么吗?谢谢

python bots telegram python-telegram-bot telegram-bot

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

传入更新的Telegram bot api限制

我正在测试Telegram bot api以获取更新

https://api.telegram.org/bot<tokenOfBot>/getUpdates

但是,我意识到我只能获得100次更新,而其他更新则不会出现.有没有办法得到我的其余更新?

api telegram-bot

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

使用 Python 请求将照片上传到 Telegram API

我看过其他关于此的问题,但我不知道我哪里错了。我可以使用如下所示的 PHP 页面毫无问题地上传文件:

<form action="https://api.telegram.org/bot190705145:AAH17XDRrPtDO1W1qHCoZ8i0_KqAAAAAAA/sendPhoto" method="post" enctype="multipart/form-data">

    <input type="text" name="chat_id" value="XXXXXXXX" />
    <input type="file" name="photo" />
    <input type="submit" value="send" />

</form>
Run Code Online (Sandbox Code Playgroud)

但我想从 Python 中通过请求来做到这一点:

url = 'https://api.telegram.org/bot190705145:AAH17XDRrPtDO1W1qHCoZ8i0_KAAAAAAAAA/sendPho    to?chat_id=XXXXXXXXX'
files = {'file':open('/Users/stephen/desktop/Sample.png', 'rb')}
r = requests.post(url, files=files)
Run Code Online (Sandbox Code Playgroud)

然后出现 r.text 错误:

u'{"ok":false,"error_code":400,"description":"[Error]: Bad Request: there is no photo in request"}'
Run Code Online (Sandbox Code Playgroud)

我想我也错误地处理了 chat_id 参数,它需要以不同的方式传递。

非常感谢任何指导!

python telegram-bot

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

Telegram API,获取发件人的电话号码?

我意识到不可能用来a Bot接收发件人的电话号码。
然而,我确实需要实现一个类似机器人的客户端,它可以响应任何向它发送消息的人。我在 apache 上使用 PHP。

它不是机器人,因为它不接受命令,而是响应任何拥有该电话号码的人发送的文本。因此,您将用户添加为联系人(使用电话号码),然后向其发送文本。

我的目标是在收到发件人的电话号码时识别它,我在Telegram API上看到有一个对等 ID,但我找不到如何获取电话号码(如果可能的话)...

php chat bots telegram telegram-bot

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

Telegram API SendVoice 方法将语音作为文件发送

我正在尝试通过 SendVoice 方法发送语音消息,但它将语音作为简单的 ogg 文件发送(不可播放)。

https://api.telegram.org/bot<token>/sendVoice?chat_id=x&voice=http://majidamiri.com/up/5.ogg
Run Code Online (Sandbox Code Playgroud)

Telegram API SendVoice中,它指出该文件应为 .ogg opus 格式,因此我使用以下代码通过 ffmpeg 将 mp3 文件转换为 opus ogg:

<?php $myConvert = exec('ffmpeg.exe -i 1.mp3 -acodec libopus -b:a 64k -vbr off -compression_level 10 5.ogg'); ?>

再次像之前一样将其作为文件发送。

我的 ogg 链接: https: //majidamiri.com/up/5.ogg

你能帮我解决这个问题吗?

谢谢你们 。

telegram-bot

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

电报机器人:ChatId ?未获取 ChatId,但 {"ok":true,"result":[]}

尝试了Telegram bot - how to get a group chat id ?中描述的所有选项 红宝石宝石 Telegram_bot

当浏览到: https: //api.telegram.org/botXXX:YYYY /getUpdates 时,我得到的是:

{“确定”:true,“结果”:[]}

我究竟做错了什么?

telegram-bot

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

无法将音频上传到 telegram 错误请求:无法获取 HTTP URL 内容

我有 mp3 的工作 url,并且我正在尝试通过此 url 将音频发送到 Telegram。它有时会起作用,但大多数时候都会出错

"A request to the Telegram API was unsuccessful. The server returned HTTP 400 
Bad Request. Response body:
[b'{"ok":false,"error_code":400,"description":"Bad Request: failed to get HTTP 
URL content"}']"
Run Code Online (Sandbox Code Playgroud)

我不明白为什么,因为我检查了大小和类型,一切都很清楚,我在 Telegram API 文档中找不到更多限制。谁知道错误原因是什么?

链接到 mp3 - http://data3.api.xn--41a.ws/vkp/cs9-5v4.userapi.com/p15/51bdb5ec5899ed.mp3

python-3.x telegram python-telegram-bot telegram-bot telegram-webhook

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

冲突:被其他getUpdates请求终止;确保只有一个机器人实例正在运行

有人遇到这样的错误吗?我该如何修复它们?

2021-11-07 08:29:38,643 - telegram.ext.updater - ERROR - Error while getting Updates: Conflict: terminated by other getUpdates request; make sure that only one bot instance is running
2021-11-07 08:29:38,644 - telegram.ext.dispatcher - ERROR - No error handlers are registered, logging exception.
    Traceback (most recent call last):
      File "/usr/local/lib/python3.8/dist-packages/telegram/ext/updater.py", line 646, in _network_loop_retry
        if not action_cb():
      File "/usr/local/lib/python3.8/dist-packages/telegram/ext/updater.py", line 597, in polling_action_cb
        updates = self.bot.get_updates(
      File "/usr/local/lib/python3.8/dist-packages/telegram/ext/extbot.py", line 222, in get_updates
        updates = super().get_updates(
      File "/usr/local/lib/python3.8/dist-packages/telegram/bot.py", line 130, in decorator
        result …
Run Code Online (Sandbox Code Playgroud)

python telegram-bot

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

如何让电报机器人将消息发布到我的频道而不是它自己的频道

我有一个电报机器人,它使用此代码向某个机器人发布消息。

import telegram
from telegram import ParseMode
def send_msg(text):
    token = '1*****:AAF*************esns'
    chat_id = "34*****4"
    bot = telegram.Bot(token=token)
    
    bot.sendMessage(chat_id=chat_id, text=text, parse_mode=ParseMode.MARKDOWN_V2)
Run Code Online (Sandbox Code Playgroud)

我想知道的是,电报机器人是否可以向我的频道发送消息,我已将其设置为管理员,而不是其自己的名为 somebot 的频道。

telegram python-telegram-bot telegram-bot

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