python telegram bot
Budget: $15 – $25 USD
I am looking for a Python developer to modify my Telegram bot that can reply to user messages.
I have a problem my telegram bot source code. Message handler always send the previous message at first and then process current message. Command hanlder has no problem.
my environmnet is python 3.6 and python-telegram-bot is 13.7
For example,(Pls refer to the attach files)
1. time(in keyboard) -> bot answer : current time is 2023-09-08 00:10:10(OK)
2. wait 1 minute
3. time(in keyboard) -> bot answer : | current time is 2023-09-08 00:10:10(NG, prev message)
time
4. bot answer : current times is 2023-09-08 00:11:10(ok)
Skills and Experience:
- Proficiency in Python
- Experience with building Telegram bots
- Understanding of Telegram API
Pls refer to my source code and the image file as follows.
from telegram import Update, ReplyKeyboardMarkup, KeyboardButton
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, CallbackContext
bot_token = 'MY Token'
updater = Updater(token=bot_token, use_context=True)
dispatcher = updater.dispatcher
# /start
def start(update, context):
context.bot.send_message(chat_id=update.effective_chat.id, text="hi, bot joined at group.", reply_markup=get_custom_keyboard())
# get time
def get_time(update, context):
import datetime
current_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
context.bot.send_message(chat_id=update.effective_chat.id, text=f"current time is {current_time}", reply_markup=get_custom_keyboard())
# message handler
def handle_message(update, context):
user_message = update.message.text
if user_message == 'time':
get_time(update, context)
else:
context.bot.send_message(chat_id=update.effective_chat.id, text=f"받은 메시지: {user_message}", reply_markup=get_custom_keyboard())
# custom keyboard
def get_custom_keyboard():
custom_keyboard = [
[KeyboardButton("time"), KeyboardButton("one option")],
[KeyboardButton("two option")]
]
return ReplyKeyboardMarkup(custom_keyboard, resize_keyboard=True)
# /start
start_handler = CommandHandler('start', start)
dispatcher.add_handler(start_handler)
# message handler
message_handler = MessageHandler(Filters.text & ~Filters.command, handle_message)
dispatcher.add_handler(message_handler)
updater.start_polling()
updater.idle()
- end of code -
I have a problem my telegram bot source code. Message handler always send the previous message at first and then process current message. Command hanlder has no problem.
my environmnet is python 3.6 and python-telegram-bot is 13.7
For example,(Pls refer to the attach files)
1. time(in keyboard) -> bot answer : current time is 2023-09-08 00:10:10(OK)
2. wait 1 minute
3. time(in keyboard) -> bot answer : | current time is 2023-09-08 00:10:10(NG, prev message)
time
4. bot answer : current times is 2023-09-08 00:11:10(ok)
Skills and Experience:
- Proficiency in Python
- Experience with building Telegram bots
- Understanding of Telegram API
Pls refer to my source code and the image file as follows.
from telegram import Update, ReplyKeyboardMarkup, KeyboardButton
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, CallbackContext
bot_token = 'MY Token'
updater = Updater(token=bot_token, use_context=True)
dispatcher = updater.dispatcher
# /start
def start(update, context):
context.bot.send_message(chat_id=update.effective_chat.id, text="hi, bot joined at group.", reply_markup=get_custom_keyboard())
# get time
def get_time(update, context):
import datetime
current_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
context.bot.send_message(chat_id=update.effective_chat.id, text=f"current time is {current_time}", reply_markup=get_custom_keyboard())
# message handler
def handle_message(update, context):
user_message = update.message.text
if user_message == 'time':
get_time(update, context)
else:
context.bot.send_message(chat_id=update.effective_chat.id, text=f"받은 메시지: {user_message}", reply_markup=get_custom_keyboard())
# custom keyboard
def get_custom_keyboard():
custom_keyboard = [
[KeyboardButton("time"), KeyboardButton("one option")],
[KeyboardButton("two option")]
]
return ReplyKeyboardMarkup(custom_keyboard, resize_keyboard=True)
# /start
start_handler = CommandHandler('start', start)
dispatcher.add_handler(start_handler)
# message handler
message_handler = MessageHandler(Filters.text & ~Filters.command, handle_message)
dispatcher.add_handler(message_handler)
updater.start_polling()
updater.idle()
- end of code -