我有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)
但在电报中我没有看到键盘.可能有什么问题?
我可以通过阅读文档非常轻松地创建一个机器人,但是 Jobqueue 并没有按照它所写的那样工作。该run_daily方法使用datetime.time对象在特定时间发送消息,但此代码既不执行发送消息的工作,也不显示任何错误。它只是继续运行
import datetime
from telegram import bot
from telegram.ext import Updater
def callback_minute(bot, job):
bot.send_message(chat_id=475838704, text='PlEaSe wOrK!')
def main():
updater = Updater()
bot = updater.bot
job = updater.job_queue
dispatcher = updater.dispatcher
job.run_daily(callback_minute, time=datetime.time(6,33,00))
updater.start_polling()
updater.idle()
if __name__ == '__main__':
main()
Run Code Online (Sandbox Code Playgroud) python job-queue python-3.x python-telegram-bot telegram-bot
我做了一个Telegram机器人,它的工作之一就是从音频文件创建样本。现在,对于发送给它的大多数音频而言,样本都很好。像这样的东西:
但是,对于某些音频,样本看起来有些奇怪:
如您所见,此文件中的波未显示!(我可以向您保证声音不是空的)
为了创建示例,我使用pydub(谢谢James!)。这是我创建示例的部分:
song = AudioSegment.from_mp3('song.mp3')
sliced = song[start*1000:end*1000]
sliced.export('song.ogg', format='ogg', parameters=["-acodec", "libopus"])
Run Code Online (Sandbox Code Playgroud)
然后使用bot.send_voice方法发送样本。像这样:
bot.send_voice(
chat_id=update.message.chat.id,
voice=open('song.ogg', 'rb'),
caption=settings.caption,
parse_mode=ParseMode.MARKDOWN,
timeout=1000
)
Run Code Online (Sandbox Code Playgroud)
Telegram Bot API的文档说:
如果希望Telegram客户端将文件显示为可播放的语音消息,请使用此方法发送音频文件。为此,您的音频必须位于使用OPUS编码的.ogg文件中(其他格式可能以音频或文档的形式发送)。
这就是为什么在这行代码中:
sliced.export('song.ogg', format='ogg', parameters=["-acodec", "libopus"])
Run Code Online (Sandbox Code Playgroud)
我用过parameters=["-acodec", "libopus"]。
谁能告诉我我在做什么错?提前致谢!
我想知道什么是最好的方法来知道手机号码是否已经注册到Telegram信使?
谢谢.
我正在使用python-telegram-bot包装器,我一直在尝试在Heroku上托管一个简单的回声电报机器人,以适应用于Google App Engine 的预先存在的示例以及维基上的webhook指南,但无济于事.
我似乎无法使webhook工作,并且机器人能够正确地回显消息.
我似乎无法弄清楚什么是错的,所以任何帮助指出我正确的方向将非常感谢!
我的尝试详述如下.
import telegram
from os import environ
from telegram.ext import Updater
from flask import Flask, request
from credentials import TOKEN, APP_URL
app = Flask(__name__)
global bot
bot = telegram.Bot(token=TOKEN)
@app.route('/' + TOKEN, methods=['POST'])
def webhook_handler():
if request.method == "POST":
# retrieve the message in JSON and then transform it to Telegram object
update = telegram.Update.de_json(request.get_json(force=True))
chat_id = update.message.chat.id
# Telegram understands UTF-8, so encode text for unicode compatibility
text …Run Code Online (Sandbox Code Playgroud) 我正在玩 Python Telegram Bot,我想将先前计算获得的参数传递给我的处理程序,例如:
def my_handler(bot, update, param):
print(param)
def main():
res = some_function()
updater.dispatcher.add_handler(CommandHandler('cmd', my_handler))
Run Code Online (Sandbox Code Playgroud)
如何将参数传递给处理程序?
我目前正在使用python-telegram-bot,基本上我想用它实现的是发送这样的电报消息:
因此,该消息包含 2 张以上的照片/视频,下方带有文本消息。
我已经尝试过的:
使用send_message方法发送消息,并包括照片 URL,但它只显示文本下方的 1 张图片
使用send_media_group发送媒体组,但此方法没有caption作为send_photo 的参数。
当我创建这篇文章时,我只是在 stackoverflow 上找到了没有任何回复的帖子... TelegramBot。Heroku Web 服务器上出现“Webhook 只能在端口 80、88、443 或 8443 上设置”错误
我的测试代码在这里:
from configparser import ConfigParser
import logging
import os
import telegram
from flask import Flask, request
from telegram.ext import Updater, Dispatcher, MessageHandler, Filters, CommandHandler
env = ConfigParser()
env.read('config.ini')
TOKEN = env['TELEGRAM']['ACCESS_TOKEN']
PORT = int(os.environ.get('PORT', '8443'))
updater = Updater(token=TOKEN)
#
#body part ( that's not important to show)
#
updater.start_webhook(listen="0.0.0.0",
port=PORT,
url_path=TOKEN)
updater.bot.set_webhook("https://tgbot00.herokuapp.com/" + TOKEN)
updater.idle()
Run Code Online (Sandbox Code Playgroud)
但服务员告诉我...
here2021-03-19T14:48:06.712894+00:00 app[web.1]: Error while bootstrap set webhook: Bad webhook: webhook can be set …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个机器人,它可以读取/接收特定频道中的所有消息并将它们发送给我。我的问题是我找不到方法来访问我的机器人中的这些消息
重要的是:
我在谷歌中搜索过,但我无法找到解决方案,而且我也确信可以做到这一点,因为已经有一些具有完全相同性能的连接机器人。任何参考或建议表示赞赏。
我有一个电报机器人,它使用此代码向某个机器人发布消息。
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-bot ×8
python ×6
telegram ×6
audio ×1
heroku ×1
job-queue ×1
linux ×1
pydub ×1
python-3.x ×1
tornado ×1