Skip to content

Commit

Permalink
Replaced depreicated reply_to_message_id
Browse files Browse the repository at this point in the history
  • Loading branch information
uak committed Sep 30, 2024
1 parent 6aab790 commit ce0c525
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
17 changes: 10 additions & 7 deletions examples/asynchronous_telebot/custom_states.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from telebot.asyncio_storage import StateMemoryStorage
from telebot.states import State, StatesGroup
from telebot.states.asyncio.context import StateContext
from telebot.types import ReplyParameters

# Initialize the bot
state_storage = StateMemoryStorage() # don't use this in production; switch to redis
Expand All @@ -23,7 +24,7 @@ async def start_ex(message: types.Message, state: StateContext):
await bot.send_message(
message.chat.id,
"Hello! What is your first name?",
reply_to_message_id=message.message_id,
reply_parameters=ReplyParameters(message_id=message.message_id),
)


Expand All @@ -34,7 +35,7 @@ async def any_state(message: types.Message, state: StateContext):
await bot.send_message(
message.chat.id,
"Your information has been cleared. Type /start to begin again.",
reply_to_message_id=message.message_id,
reply_parameters=ReplyParameters(message_id=message.message_id),
)


Expand All @@ -43,7 +44,8 @@ async def any_state(message: types.Message, state: StateContext):
async def name_get(message: types.Message, state: StateContext):
await state.set(MyStates.age)
await bot.send_message(
message.chat.id, "How old are you?", reply_to_message_id=message.message_id
message.chat.id, "How old are you?",
reply_parameters=ReplyParameters(message_id=message.message_id),
)
await state.add_data(name=message.text)

Expand All @@ -64,7 +66,7 @@ async def ask_color(message: types.Message, state: StateContext):
message.chat.id,
"What is your favorite color? Choose from the options below.",
reply_markup=keyboard,
reply_to_message_id=message.message_id,
reply_parameters=ReplyParameters(message_id=message.message_id),
)


Expand All @@ -84,7 +86,7 @@ async def ask_hobby(message: types.Message, state: StateContext):
message.chat.id,
"What is one of your hobbies? Choose from the options below.",
reply_markup=keyboard,
reply_to_message_id=message.message_id,
reply_parameters=ReplyParameters(message_id=message.message_id),
)


Expand Down Expand Up @@ -123,7 +125,8 @@ async def finish(message: types.Message, state: StateContext):
)

await bot.send_message(
message.chat.id, msg, parse_mode="html", reply_to_message_id=message.message_id
message.chat.id, msg, parse_mode="html",
reply_parameters=ReplyParameters(message_id=message.message_id),
)
await state.delete()

Expand All @@ -134,7 +137,7 @@ async def age_incorrect(message: types.Message):
await bot.send_message(
message.chat.id,
"Please enter a valid number for age.",
reply_to_message_id=message.message_id,
reply_parameters=ReplyParameters(message_id=message.message_id),
)


Expand Down
17 changes: 10 additions & 7 deletions examples/custom_states.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from telebot.states import State, StatesGroup
from telebot.states.sync.context import StateContext
from telebot.storage import StateMemoryStorage
from telebot.types import ReplyParameters

# Initialize the bot
state_storage = StateMemoryStorage() # don't use this in production; switch to redis
Expand All @@ -24,7 +25,7 @@ def start_ex(message: types.Message, state: StateContext):
bot.send_message(
message.chat.id,
"Hello! What is your first name?",
reply_to_message_id=message.message_id,
reply_parameters=ReplyParameters(message_id=message.message_id),
)


Expand All @@ -35,7 +36,7 @@ def any_state(message: types.Message, state: StateContext):
bot.send_message(
message.chat.id,
"Your information has been cleared. Type /start to begin again.",
reply_to_message_id=message.message_id,
reply_parameters=ReplyParameters(message_id=message.message_id),
)


Expand All @@ -44,7 +45,8 @@ def any_state(message: types.Message, state: StateContext):
def name_get(message: types.Message, state: StateContext):
state.set(MyStates.age)
bot.send_message(
message.chat.id, "How old are you?", reply_to_message_id=message.message_id
message.chat.id, "How old are you?",
reply_parameters=ReplyParameters(message_id=message.message_id),
)
state.add_data(name=message.text)

Expand All @@ -65,7 +67,7 @@ def ask_color(message: types.Message, state: StateContext):
message.chat.id,
"What is your favorite color? Choose from the options below.",
reply_markup=keyboard,
reply_to_message_id=message.message_id,
reply_parameters=ReplyParameters(message_id=message.message_id),
)


Expand All @@ -85,7 +87,7 @@ def ask_hobby(message: types.Message, state: StateContext):
message.chat.id,
"What is one of your hobbies? Choose from the options below.",
reply_markup=keyboard,
reply_to_message_id=message.message_id,
reply_parameters=ReplyParameters(message_id=message.message_id),
)


Expand Down Expand Up @@ -124,7 +126,8 @@ def finish(message: types.Message, state: StateContext):
)

bot.send_message(
message.chat.id, msg, parse_mode="html", reply_to_message_id=message.message_id
message.chat.id, msg, parse_mode="html",
reply_parameters=ReplyParameters(message_id=message.message_id),
)
state.delete()

Expand All @@ -135,7 +138,7 @@ def age_incorrect(message: types.Message):
bot.send_message(
message.chat.id,
"Please enter a valid number for age.",
reply_to_message_id=message.message_id,
reply_parameters=ReplyParameters(message_id=message.message_id),
)


Expand Down

0 comments on commit ce0c525

Please sign in to comment.