Hotel California¶
In this example we show how to keep people in the same channel.
View the source code of this example
How to preserve state of the hotel?¶
In this example a bot is representing a distinct hotel instance. So there is a need to know, for each bot, is the hotel is retaining visitors or not.
This is done with bot.remember()
and bot.recall()
calls respectively.
Under the hood, each bot is equipped with a dedicated data store.
How to know that someone is joining or leaving?¶
Shellbot implements a simple event dispatcher, that is used in this example to detect when people join or leave a channel.
For this, we create a python object with functions on_join()
and
on_leave()
. Then this handler is registered for the events join
and
leave
generated by the engine.
How to add participants to a channel?¶
You can add a person to a channel by invoking bot.add_participant()
with
the e-mail address of a new participant. Note that some restrictions may apply,
depending on the commercial agreement with the cloud service provider.
Commands: open, close, hotel¶
The commands prevent or allow people to leave the Hotel, or report on current status.
- open
- This command puts the bot in “sticky” mode. If a participant leaves a channel for some reason, he is automatically added back after 5 seconds.
- close
- After this command, participants can leave the channel freely. They are not forced to come back anymore
- hotel
- This command displays the current mode of working. Can participants go away or not?
How to run this example?¶
To run this script you have to provide a custom configuration, or set environment variables instead:
CHANNEL_DEFAULT_PARTICIPANTS
- Mention at least your e-mail addressCISCO_SPARK_BOT_TOKEN
- Received from Cisco Spark on bot registrationSERVER_URL
- Public link used by Cisco Spark to reach your server
The token is specific to your run-time, please visit Cisco Spark for Developers to get more details:
For example, if you run this script under Linux or macOs with support from ngrok for exposing services to the Internet:
export CHANNEL_DEFAULT_PARTICIPANTS="alice@acme.com"
export CISCO_SPARK_BOT_TOKEN="<token id from Cisco Spark for Developers>"
export SERVER_URL="http://1a107f21.ngrok.io"
python hotel_california.py