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

Function finish

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

Source from the content-addressed store, hash-verified

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