我想使用它的深层链接api通过电报设置身份验证。
为了进行身份验证,在我的应用程序中,我要求用户单击以下链接:
https://telegram.me/myloginbot?start=somesecretkey
Run Code Online (Sandbox Code Playgroud)
如果我正确理解文档,我应该期望机器人回显somesecretky到我的服务器。
现在,我不清楚文档的这一步:
- 配置 webhook 处理器以使用传入消息中以 /start 开头的参数查询 Memcached
如果我理解正确,我需要进行配置,myloginbot以便当用户单击机器人页面上的开始按钮时,机器人会向我的服务器回显一个包含somesecretkey一些用户信息的 URL 。但我不知道该怎么做。
在这个答案中,建议:
- 让机器人通过查询数据库或键值存储的 unique_code 来检索用户名。
但我不知道如何让机器人查询(大概是远程)数据库。
所以真的很感谢你的提示。
我有很多电报频道,他们以 24\7 的格式发送消息
或按某种顺序这些词
我的想法是创建应用程序来检查每个频道的消息,如果它采用上述格式,则将其重定向到我的频道。
电报api允许吗?
我正在开发一个电报机器人,可根据要求显示来自多个网络摄像头的图像。我从 url 获取图像,然后发送给用户(使用 bot.sendPhoto() )我的问题是,对于任何给定的网络摄像头,文件名都不会改变,而且照片似乎是从电报的缓存中发送的。因此,它将显示第一次请求图像时的图像。
我想过从 url 下载图像,使用变量名称保存(例如带有时间戳的名称),然后将其发送到聊天室,这似乎是一个不雅的解决方案,并希望有更好的解决方案。就像强制图像不被缓存在电报服务器上一样。
我正在使用 python-telegram-bot 包装器,但我不确定它是否特定于此。
有任何想法吗?我试过搜索,但到目前为止我发现的很少。提前致谢。
我是电报机器人的新手。我有一个简单的问题,我遵循了电报机器人文档,这是我的代码:
from telegram.ext import Updater,CommandHandler,MessageHandler, Filters
import logging
updater = Updater(token='<Enter Token>')
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
dispatcher = updater.dispatcher
def start(bot, update):
bot.sendMessage(chat_id=update.message.chat_id, text="I'm a bot, please talk to me!")
def caps(bot, update, args):
text_caps = ' '.join(args).upper()
bot.sendMessage(chat_id=update.message.chat_id, text=text_caps)
start_handler = CommandHandler('start', start)
dispatcher.add_handler(start_handler)
caps_handler = CommandHandler('caps', caps, pass_args=True)
dispatcher.add_handler(caps_handler)
updater.start_polling()
Run Code Online (Sandbox Code Playgroud)
现在当我去执行我的脚本时。
如果我输入 /caps hi,它会按预期返回 HI。
但我想当我输入 / 时,它会在弹出窗口中提供类似 /cap 的选项。但事实并非如此
任何帮助将不胜感激。
有没有办法自定义键盘上的按钮位置?
例子:我们有
import telegram
def start(bot, update):
kb = [[telegram.KeyboardButton('/command1')],
[telegram.KeyboardButton('/command2')],
[telegram.KeyboardButton('/command3')]]
kb_markup = telegram.ReplyKeyboardMarkup(kb, resize_keyboard=True)
bot.send_message(chat_id=update.message.chat_id,
text="Welcome!",
reply_markup=kb_markup)
Run Code Online (Sandbox Code Playgroud)
结果,我们有带 3 个按钮的键盘,每个按钮都在自己的行上。
我想在第一行有 2 个按钮,在第二行有 1 个按钮。是否可以?
电报 api 的一些奇怪的事情。我正在尝试从电报机器人发送音频并顺便更改表演者和标题,但我不能。首先我以为我犯了一个错误,但不是!我试图从浏览器搜索行做同样的事情,因为没有机会做错什么,也没有结果!也许你可以尝试做同样的事情?这会很棒,因为我不知道出了什么问题。我正在尝试使用 pyTelegramBotAPI 在 Python 上执行此操作。例如代码:
import telebot
import const
#??????????? ? ????
bot = telebot.TeleBot(const.token)
@bot.message_handler(content_types=["text"])
def handle_command(message):
a = bot.send_audio(message.from_user.id, musicurl, caption=None, duration=None, performer="Pharik", title="hfdhdfh",
reply_to_message_id=None)
print(a.audio.performer)
print(a.audio.title)
bot.polling(none_stop=True, interval=0)
Run Code Online (Sandbox Code Playgroud) 以下代码请求用户的位置和联系:
def contact(bot, update):
dp = DjangoTelegramBot.dispatcher
con_keyboard = KeyboardButton(text="send_contact", request_contact=True)
loc_keyboard = KeyboardButton(text="send_location", request_location=True)
custom_keyboard = [[ con_keyboard ,loc_keyboard]]
reply_markup = ReplyKeyboardMarkup(custom_keyboard)
bot.sendMessage(update.message.chat_id,
text="Would you mind sharing your location and contact with me",
reply_markup=reply_markup)
Run Code Online (Sandbox Code Playgroud)
我的问题是用户点击send_contact按钮后如何访问电话号码?
PS:我正在使用python-telegram-bot和django-telegrambot
我正在使用处理程序在Telegram机器人中工作。在他们使用命令后,我需要在其中获取用户名或用户ID。
我的密码
import telebot #Telegram Bot API
bot = telebot.TeleBot(<BotToken>)
@bot.message_handler(commands=['info'])
def send_welcome(message):
name = bot.get_me()
print(name)
bot.reply_to(message, "Welcome")
bot.polling()
Run Code Online (Sandbox Code Playgroud)
但是,我仅获得有关该机器人的信息。我无法获取有关使用处理程序的用户的信息。
输出值
{'first_name': 'SPIOTSYSTEMS', 'id': 581614234, 'username': 'spiotsystems_bot', 'is_bot': True, 'last_name': None, 'language_code': None}
Run Code Online (Sandbox Code Playgroud)
如何获得使用info命令的用户的用户ID或名称?我应该使用哪种方法?请指教。
注意:
我的机器人与Telegram组链接。并且出于安全原因,我已从我的MVC中删除了Telegram TOKEN。
我想通过使用库 python-telegram-bot 和 discord.py (版本 1.0.0)来制作一个在不和谐和电报之间进行通信的机器人。然而问题是 discord.py 使用异步函数和 python-telegram-bot 线程。使用下面的代码,对于在 discord 中发布的消息(机器人将它们正确发送到电报),一切正常,但反之则行不通(机器人从电报获取消息并将其发送到不和谐)。我以前在尝试channel.send在同步函数中运行 discords函数时遇到了语法/运行时错误的问题(因此要么只返回一个生成器对象,要么抱怨我无法使用await在同步函数中使用)。然而,与此同时,python-telegram-bot 的MessageHandler需要一个同步函数,所以当给他一个异步函数时,Python 抱怨从来没有为异步函数调用“await”。我现在试图用async_to_sync方法从asgiref库运行我的异步broadcastMsg从MessageHandler,但是代码仍然不将消息发送给不和谐!它似乎正确地调用了该函数,但仅在 line 之前print('I get to here')。没有错误显示,也没有不和谐的消息弹出。我想这与我必须在 discord.py 事件循环中将该函数注册为任务这一事实有关,但是注册仅在它发生之前才有效botDiscord.run(TOKENDISCORD)已经被执行,这当然必须在之前发生。因此,将我的问题归结为一个问题:我如何能够与来自另一个线程(来自电报MessageHandler)的 discord.py 事件循环进行交互。或者,如果这是不可能的:如何在不处于 discord.py 事件循环中的情况下使用 discord.py 发送消息?
感谢您的帮助
import asyncio
from asgiref.sync import async_to_sync
from telegram import Message as TMessage
from telegram.ext import (Updater,Filters,MessageHandler)
from discord.ext import commands
import discord
TChannelID = 'someTelegramChannelID'
DChannel = 'someDiscordChannelObject'
#%% define functions / commands
prefix = …Run Code Online (Sandbox Code Playgroud) 我有一个电报机器人,可以在群组中发送消息。我希望电报机器人不时更改其“名称” - 就像用户一样。这可能吗?这意味着当我看到来自机器人的消息时,它可以说“ABCbot”,但后来它可以说“DEFbot”。让我知道!
python-telegram-bot telegram-bot telegram-webhook node-telegram-bot-api