Skip to content

Commit 204ea9b

Browse files
committed
Improve callback server example
1 parent 80037b5 commit 204ea9b

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

examples/callback.py

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import functools
12
import ssl
23

34
import logbook
@@ -15,6 +16,15 @@ async def handle_message(message):
1516
print('Got message ({}): {}'.format(repr(message), message))
1617

1718

19+
async def on_startup(connection, application):
20+
message = e2e.TextMessage(
21+
connection=connection,
22+
to_id='ECHOECHO',
23+
text='Hi!'
24+
)
25+
await message.send()
26+
27+
1828
async def create_application():
1929
# Create connection instance
2030
connection = Connection(
@@ -23,10 +33,16 @@ async def create_application():
2333
key='private:YOUR_PRIVATE_KEY'
2434
)
2535

26-
# Create the application and register the handler for incoming messages
36+
# Create the web server application
2737
application = e2e.create_application(connection)
38+
39+
# Register the handler for incoming messages
2840
e2e.add_callback_route(
2941
connection, application, handle_message, path='/gateway_callback')
42+
43+
# Register startup hook (to send an outgoing message in this example)
44+
application.on_startup.append(functools.partial(on_startup, connection))
45+
3046
return application
3147

3248

0 commit comments

Comments
 (0)