Chat coordination
Background coordinator processes¶
Bubblescript provides some concepts to allow the users of a bot to do things together.
Sending internal messages¶
Using emit with to: syntax, you can send an event (with optional
payload) to another user. This way, you can create a chatbot which
relays messages between two users.
However, in order to do this, you need to know the other user's address, which is the address of the conversation between the other user and the bot.
The master coordinator¶
There is a types of script which is special and runs as separate "thread" in the
bot runtime. This is called the master process: a single background process
that can be used to relay information between different users, perform tasks in
the background, and do several other things.
The master script is a special process which runs as a separate
process. There is at most one master process per bot:

emit¶
From a user script, you can emit something to :master. It receives
the event and can then relay the information to another user, or send
(emit) something back to the sender.
emit "hello", to: :master
The master process can catch this "hello" event and then perform
something, update some administration or emit something back:
task event: "hello" do
users = users + [event.sender]
# let the user know we have registered it
emit "ok", to: event.sender
end
query¶
Sends an event to the given user, and waits for the reply.
reply = query :master, "ping"
say reply
In the other script, define a task or dialog that catches the ping event, and use the reply construct to send a payload back:
task event: "ping" do
reply "pong"
end
Make sure that the handling task / dialog in the other process finishes quickly. If there is no reply received within 1 second, the value :timeout is returned in the calling process.
The ChatterBot in the botsquad examples is a good example of how a
master script is used to create a group chat in which all chat
members relay all text messages and images they send to each other.