所述sendPhoto命令需要一个参数photo定义为InputFile or String.
API文档告诉:
Photo to send. You can either pass a file_id as String to resend a photo
that is already on the Telegram servers, or upload a new photo using
multipart/form-data.
Run Code Online (Sandbox Code Playgroud)
和
InputFile
This object represents the contents of a file to be uploaded. Must be
posted using multipart/form-data in the usual way that files are
uploaded via the browser.
Run Code Online (Sandbox Code Playgroud)
所以我尝试了这种方法
$bot_url = "https://api.telegram.org/bot<bot_id>/";
$url = $bot_url . "sendPhoto?chat_id=" . $chat_id;
$ch …Run Code Online (Sandbox Code Playgroud) 我使用setWebhook作为我的telegram-bot,现在我需要使用getUpdates.我已经阅读了文档,他们说,我只能使用一种方法.
问题是,我在控制台中:
{"ok":false,"error_code":409,"description":"Error: Conflict: another webhook is active"}
Run Code Online (Sandbox Code Playgroud)
所以问题是,如何使用UNSET webhook并使用getUpdates?
我有Telegram Bot Api和"ReplyKeyboard"的问题.我正在使用Python 2.7并发送帖子请求:
TelegramAPI.post(TELEGRAM_URL + "sendMessage", data=dict(chat_id=CHAT_ID, text="", keyboard={'keyboard': keyboard, 'one_time_keyboard': False, 'resize_keyboard': True})
Run Code Online (Sandbox Code Playgroud)
这种格式的键盘:
[["A button"], ["B button"]]
Run Code Online (Sandbox Code Playgroud)
但在电报中我没有看到键盘.可能有什么问题?
当我向Telegram Bot发送消息时,它没有任何问题.
我想限制访问,以便我和只有我可以向它发送消息.
我怎样才能做到这一点?
我需要用照片发送电报长文本但电报图像标题有200个字符限制.如何使用php和bot发送带有照片的长文本?sendPhoto方法有200个字符限制.我看到一个电报机器人它发送长文本和照片看到我的样本照片.

我在Python中使用以下代码从机器人向自己发送消息.
import requests
token = '320835125:AAFUUC-fdo_EFzsCjvmxu8HBk7qVzZXXXXX'
method = 'sendMessage'
myuserid = 1949275XX
response = requests.post(
url='https://api.telegram.org/bot{0}/{1}'.format(token, method),
data={'chat_id': myuserid, 'text': 'hello friend'}
).json()
print(response)
Run Code Online (Sandbox Code Playgroud)
但这会回来 {'description': 'Bad Request: chat not found', 'error_code': 400, 'ok': False}
我究竟做错了什么?我myuserid通过发送/getid来@myidbot获得我的令牌@BotFather
我开始开发一个与电报机器人相关的宠物项目。问题之一是,如何从机器人下载语音消息?
任务:需要从电报机器人下载音频文件并保存在项目文件夹中。
GetUpdates https://api.telegram.org/bot /getUpdates:
{"duration":2,"mime_type":"audio/ogg","file_id":"<file_id>","file_unique_id":"<file_unique_id>","file_size":8858}}}]}
Run Code Online (Sandbox Code Playgroud)
我检查了pyTelegramBotAPI文档,但没有找到确切如何下载文件的解释。
我根据文档创建了代码:
@bot.message_handler(content_types=['voice'])
def voice_processing(message):
file_info = bot.get_file(message.voice.file_id)
file = requests.get('https://api.telegram.org/file/bot{0}/{1}'.format(cfg.TOKEN, file_info.file_path))
Run Code Online (Sandbox Code Playgroud)
print(type(file), file)
------------------------------------------------------------
Output: <class 'requests.models.Response'>, <Response [200]>
Run Code Online (Sandbox Code Playgroud)
我还发现了一个例子,作者以块的形式下载音频。我不明白到底是怎么回事,但它使用了类似的功能:
def read_chunks(chunk_size, bytes):
while True:
chunk = bytes[:chunk_size]
bytes = bytes[chunk_size:]
yield chunk
if not bytes:
break
Run Code Online (Sandbox Code Playgroud) python python-requests telegram python-telegram-bot telegram-bot
我正在尝试在电报聊天中发送消息。我希望电报设置只能通过官方 UI 完成,因为我希望它可能由最终用户完成。
这是我所做的电报设置:
XXXXXXX_bot通过获取令牌与 Botfather 创建了机器人:没问题TestChannelXXXXXXX_botTestChannelTestChannelChatTestChannelChatXXXXXXX_bot以下是频道管理员的设置:
最终,电报 UI 中的聊天/群组设置如下:
我进行以下 http 调用:
GET https://api.telegram.org/botXXXXXXTOKENXXXXXXX/sendMessage?chat_id=@TestChannelChat&text=coucou
Run Code Online (Sandbox Code Playgroud)
这给了我以下答案:
GET https://api.telegram.org/botXXXXXXTOKENXXXXXXX/sendMessage?chat_id=@TestChannelChat&text=coucou
Run Code Online (Sandbox Code Playgroud)
我还做了以下操作(绕过实际聊天并直接在频道中发布消息):
GET https://api.telegram.org/botXXXXXXTOKENXXXXXXX/sendMessage?chat_id=@TestChannel&text=coucou
Run Code Online (Sandbox Code Playgroud)
这给了我以下答案:
{
"ok": false,
"error_code": 403,
"description": "Forbidden: bot is not a member of the supergroup chat"
}
Run Code Online (Sandbox Code Playgroud)
一个简单的问题,由于机器人也用于广播消息,我缺少其设置的哪一部分?
我创建了一个电报机器人并将其添加到我的电报频道中。现在,当我的 python 程序中发生某些情况时,我想使用它向我的频道发送消息。例如,我有一个 python 程序,每 15 秒检查一次天气,当天气发生变化时,我希望我的机器人将新的天气信息发送到我的电报频道。
所以我的问题是,我该怎么做?我陷入困境,因为 python-telegram-bot 需要用户发送消息才能触发,或者需要预定订单,而我无法安排它,因为我不知道天气何时会发生变化。