Python, Deep Link directing User to Bot Private Chat after Button click - python

I have a question that I can‘t resolve it. I am using Telebot API to create a Telegram Bot, all I want to do is, when Bot sends a Button in a Group, when User clicks this Button first time, to be redirected in the Bots Private Message "http://telegram.me/<Bot_Username>?start=start", where User can Start the Bot.
My code in Python:
#bot.callback_query_handler(func=lambda call: 'begin_config' in call.data)
def query(call):
bot.message.reply_to(text="http://telegram.me/<BotName>?start=start")
#bot.message_handler(commands=['bot_config'])
def bot_config(message):
text_to_post = "Greetings, Bot here, hit the Button to configure"
markup = telebot.types.InlineKeyboardMarkup()
markup.add(telebot.types.InlineKeyboardButton(text='Bot configuration', callback_data='begin_config'))
bot.reply_to(message, text_to_reply, reply_markup=markup)
I am getting the Error: AttributeError: 'TeleBot' object has no attribute 'message'
When I use
call.message.reply_markup(text="http://telegram.me/?start=start")
I am getting the Error: AttributeError: TypeError: 'InlineKeyboardMarkup' object is not callable
I just want User, when he clicks the Button [Bot configuration] first time to get the Private Chat of the Bot, where the User can start the Bot.
enter image description here

Thank's for anyone attempting to solve my Problem, but I solved it by myself. It was unclear for me since Bot can't send Private Messages to Users, as long as they have not Start-ed the Bot. So I wanted to redirect the User to Start my Bot, by clicking the Button posted by the Bot in the Group.
In this case the Callback is not needed at all, just create a Button containing the Bots Address as Url and send it to ChatID, when User clicks the Button, it automatically invites the User to Start the Bot, after that User can Start the Bot and can get Private Messages.
markup = telebot.types.InlineKeyboardMarkup()
markup.add(telebot.types.InlineKeyboardButton(text='Bot configuration',
url="https://t.me/<Bot_Name>"))
bot.send_message(chat_id=chat_id, caption=text_to_post,
reply_markup=markup, parse_mode=ParseMode.HTML)

Related

How to fix message_post should only be call to post message on record. Use message_notify instead in odoo 14?

When we assign any lead to salesperson the mail should sent and its reflected under Technical--> Emails.
Open that email record and when we click Reply button and after Send the error should be invoked
How to fix that.[Email Record ImageAfter click on send button](https://i.stack.imgur.com/WeGWu.png)
Simple i have to reply them in click on Reply button as on Odoo Default working.

Python Telegram Bot + 3rd Party Listener

I'm working with Python Telegram Bot https://python-telegram-bot.readthedocs.io/
I'm trying to implement a bot function into a 3rd party listener, so when the handle_event() is fired, with a telegram username as parameter, the bot bans that member from the group. here we go with an example:
def handle_event(event):
result = offerCancelled_event.processReceipt(receipt)
#Double check if we got a result
if(result):
#Set telegram user
telegram_user = "Ulvur"
users.remove(telegram_user)
file = open('users.txt', 'w+')
for user in users:
file.write('%s\n' % user)
file.close()
if(telegram_user not in users):
Update.effective_chat.ban_member(telegram_user)
Following code is returning AttributeError: 'property' object has no attribute 'ban_member' when function is fired.
Update is a class and the property Update.effective_chat can only be properly evaluated for instances of that class. If you want to make simple calls to the Bot API, you should instantiate an instance of the telegram.Bot class and call its methods - in your case Bot.ban_chat_member. Please see the Introduction to the API for a more detailed explanation of how to use the API methods.

Python Telegram Bot. Get message to which given message replies

I want to develop a Telegram bot, that acts as a bookmarking system. It should process commands that reply to other messages. The instance:
I use python-telegram-bot for development and it seems that there is no way to see that message to which /important replies. I found the Update.message.reply_to_message object, which works only when a user replies to a message from the bot itself.
def important_handler(update: Update, context: CallbackContext):
reply_to_message = update.message.reply_to_message
if reply_to_message is None:
logger.error('reply_to_message is None. But it shouldn\'t.')
update.message.reply_text('There is no message attached. Try again.')
return
# ... business logic
Is there any way to get reply_to_message attribute (or an alternative) for all the replies? Thanks in advice;)
I had the same problem. It only worked when a user replied to the bot. My issue was that the bot had Privacy Mode enabled. Once I disabled it with Botfather via /setprivacy and then it worked.

post in private channel

I'm trying to write a telegram python bot that posts in my private channel for Authorized users only
I succeeded to make a bot that work only for Authorized users but i cant finish that and cant find anything that can help, need to know how can i make that Authorized user can save post in memory and press in the botton Whenever he wants to post in the channel
stuck from here ;
#restricted
def start(update, context):
keyboard = [[InlineKeyboardButton("change post", callback_data='1'),
InlineKeyboardButton("show saved post", callback_data='2')],
[InlineKeyboardButton("post in channel", callback_data='3')]]
anyone can help me please? Thanks in advance

Python Telegram Bot - How to update the text of the last message my bot has sent

I'm using python-telegram-bot (python-telegram-bot.org) to communicate with Telegram from Python3
I would like to update the last reply I sent.
Currently, the code below sends the message and then sends
another message 5 seconds later.
def echo(bot, update):
update.message.reply_text("Sorry, you're on your own, kiddo.")
time.sleep(5)
update.message.reply_text("Seriously, you're on your own, kiddo.")
I'd like to update the last message instead.
I tried
bot.editMessageText("Seriously, you're on your own, kiddo.",
chat_id=update.message.chat_id,
message_id=update.message.message_id)
which works in the examples to update replace an inline keyboard with a a message, but that crashes (and does not update the last message I sent as a bot).
I believe the order of your arguments in edit_message_text() is wrong. Check out the docs for that:
def echo(bot, update):
# Any send_* methods return the sent message object
msg = update.message.reply_text("Sorry, you're on your own, kiddo.")
time.sleep(5)
# you can explicitly enter the details
bot.edit_message_text(chat_id=update.message.chat_id,
message_id=msg.message_id,
text="Seriously, you're on your own, kiddo.")
# or use the shortcut (which pre-enters the chat_id and message_id behind)
msg.edit_text("Seriously, you're on your own, kiddo.")
The docs for the shortcut message.edit_text() is here.

Categories