Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced deprecated reply_to_message_id with reply_parameters in custom_states examples #2399

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading