forked from mixer/beam-client-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.py
29 lines (21 loc) · 770 Bytes
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"""
Example chat bot that monitors incoming messages and sends "Hi!" every second.
"""
from chatty import create
import config
from tornado.ioloop import PeriodicCallback, IOLoop
from functools import partial
if __name__ == "__main__":
chat = create(config)
# Tell chat to authenticate with the beam server. It'll throw
# a chatty.errors.NotAuthenticatedError if it fails.
chat.authenticate(config.CHANNEL)
# Listen for incoming messages. When they come in, just print them.
chat.on("message", partial(print, "RECEIVE:"))
# Create a timer that sends the message "Hi!" every second.
PeriodicCallback(
lambda: chat.message('Hi!'),
1000
).start()
# Start the tornado event loop.
IOLoop.instance().start()