MCPcopy Create free account
hub / github.com/eternnoir/pyTelegramBotAPI / finish

Function finish

examples/asynchronous_telebot/custom_states.py:97–131  ·  view source on GitHub ↗
(message: types.Message, state: StateContext)

Source from the content-addressed store, hash-verified

95 state=MyStates.hobby, text=["Reading", "Traveling", "Gaming", "Cooking"]
96)
97async def finish(message: types.Message, state: StateContext):
98 async with state.data() as data:
99 name = data.get("name")
100 age = data.get("age")
101 color = data.get("color")
102 hobby = message.text # Get the hobby from the message text
103
104 # Provide a fun fact based on color
105 color_facts = {
106 "Red": "Red is often associated with excitement and passion.",
107 "Green": "Green is the color of nature and tranquility.",
108 "Blue": "Blue is known for its calming and serene effects.",
109 "Yellow": "Yellow is a cheerful color often associated with happiness.",
110 "Purple": "Purple signifies royalty and luxury.",
111 "Orange": "Orange is a vibrant color that stimulates enthusiasm.",
112 "Other": "Colors have various meanings depending on context.",
113 }
114 color_fact = color_facts.get(
115 color, "Colors have diverse meanings, and yours is unique!"
116 )
117
118 msg = (
119 f"Thank you for sharing! Here is a summary of your information:\n"
120 f"First Name: {name}\n"
121 f"Age: {age}\n"
122 f"Favorite Color: {color}\n"
123 f"Fun Fact about your color: {color_fact}\n"
124 f"Favorite Hobby: {hobby}"
125 )
126
127 await bot.send_message(
128 message.chat.id, msg, parse_mode="html",
129 reply_parameters=ReplyParameters(message_id=message.message_id),
130 )
131 await state.delete()
132
133
134# Handler for incorrect age input

Callers

nothing calls this directly

Calls 5

ReplyParametersClass · 0.90
dataMethod · 0.45
getMethod · 0.45
send_messageMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…