shellbot.channel module

class shellbot.channel.Channel(attributes=None)[source]

Bases: object

Represents a chat channel managed by a space

A channel is a group of interactions within a chat space. It features a unique identifier, and a title. It also have participants and content.

This class is a general abstraction of a communication channel, that can easily been adapted to various chat systems. It has been designed as a dictionary wrapper, with minimum exposure to shellbot, while enabling the transmission of rich information through serialization.

Instances of Channel are created within a Space object, and consumed by it as well.

For example, to create a channel with a given title, you could write:

channel = space.create(title='A new channel')
bot.say(u"I am happy to join {}".format(channel.title))

And to change the title of the channel:

channel.title = 'An interesting place'
space.update(channel)

Direct channels support one-to-one interactions between the bot and one person. The creation of a direct channel can only be indirect, by sending an invitation to the target person. For example:

bot.say(person='foo.bar@acme.com',
        text='Do you want to deal with me?')

If the person receives and accepts the invitation, the engine will receive a join event and load a new bot devoted to the direct channel. So, at the end of the day, when multiple persons interact with a shellbot, this involve both group and direct channels.

For example, if you create a shellbot named shelly, that interacts with Alice and with Bob, then shelly will overlook multiple bots and channels:

  • shelly main channel (bot + channel + store + state machine)
  • direct channel with Alice (bot + channel + store + state machine)
  • direct channel with Bob (bot + channel + store + state machine)
get(key, default=None)[source]

Returns the value of one attribute :param key: name of the attribute :type key: str

Parameters:default (str or other serializable object) – default value of the attribute
Returns:value of the attribute
Return type:str or other serializable object or None

The use case for this function is when you adapt a channel that does not feature an attribute that is expected by shellbot. More specifically, call this function on optional attributes so as to avoid AttributeError

id

Returns channel unique id

Return type:str
is_direct

Indicates if this channel is only for one person and the bot

Return type:str

A channel is deemed direct when it is reserved to one-to-one interactions. Else it is considered a group channel, with potentially many participants.

is_moderated

Indicates if this channel is moderated

Return type:str

A channel is moderated when some participants have specific powers that others do not have. Else all participants are condidered the same and peer with each others.

title

Returns channel title

Return type:str