shellbot.spaces.local module¶
-
class
shellbot.spaces.local.
LocalSpace
(context=None, ears=None, fan=None, **kwargs)[source]¶ Bases:
shellbot.spaces.base.Space
Handles chat locally
This class allows developers to test their commands interface locally, without the need for a real API back-end.
If a list of commands is provided as input, then the space will consume all of them and then it will stop. All kinds of automated tests and scenarios can be build with this approach.
Example of automated interaction with some commands:
engine = Engine(command=Hello(), type='local') engine.space.push(['help', 'hello', 'help help']) engine.configure() engine.run()
If no input is provided, then the space provides a command-line interface so that you can play interactively with your bot. This setup is handy since it does not require access to a real chat back-end.
-
DEFAULT_PROMPT
= u'> '¶
-
add_participant
(id, person, is_moderator=False)[source]¶ Adds one participant
Parameters: - id (str) – the unique id of an existing channel
- person (str) – e-mail address of the person to add
- is_moderator (True or False) – if this person has special powers on this channel
-
check
()[source]¶ Check settings
This function reads key
local
and below, and update the context accordingly.This function also selects the right input for this local space. If some content has been provided during initialisation, it is used to simulate user input. Else stdin is read one line at a time.
-
create
(title, **kwargs)[source]¶ Creates a channel
Parameters: title (str) – title of a new channel Returns: Channel This function returns a representation of the local channel.
-
delete
(id, **kwargs)[source]¶ Deletes a channel
Parameters: id (str) – the unique id of an existing channel
-
get_by_id
(id, **kwargs)[source]¶ Looks for an existing channel by id
Parameters: id (str) – identifier of the target channel Returns: Channel instance or None
-
get_by_title
(title, **kwargs)[source]¶ Looks for an existing channel by title
Parameters: title (str) – title of the target channel Returns: Channel instance or None
-
list_participants
(id)[source]¶ Lists participants to a channel
Parameters: id (str) – the unique id of an existing channel Returns: a list of persons Return type: list of str Note: this function returns all participants, except the bot itself.
-
on_init
(input=None, **kwargs)[source]¶ Handles extended initialisation parameters
Parameters: input (str or list of str) – Lines of text to be submitted to the chat Example:
space = LocalSpace(input='hello world')
Here we create a new local space, and simulate a user typing ‘hello world’ in the chat space.
-
on_message
(item, queue)[source]¶ Normalizes message for the listener
Parameters: - item (dict) – attributes of the inbound message
- queue (Queue) – the processing queue
This function prepares a Message and push it to the provided queue.
-
post_message
(id=None, text=None, content=None, file=None, person=None, **kwargs)[source]¶ Posts a message
Parameters: - id (str) – the unique id of an existing channel
- person (str) – address for a direct message
- text (str) – message in plain text
- content (str) – rich format, such as MArkdown or HTML
- file (str) – URL or local path for an attachment
-
pull
()[source]¶ Fetches updates
This function senses most recent item, and pushes it to the listening queue.
-
push
(input)[source]¶ Adds more input to this space
Parameters: input (str or list of str) – Simulated user input This function is used to simulate input user to the bot.
-
remove_participant
(id, person)[source]¶ Removes one participant
Parameters: - id (str) – the unique id of an existing channel
- person (str) – e-mail address of the person to remove
-