Events

Events in opsdroid represent things that happen on the services that opsdroid connects to. They are both sent and received by the connectors.

All events are a subclass of the base Event class. Each event also defines its own set of attributes which are specific to that type of event.

Event

The base Event class has the following attributes and methods.

… py:class:: Event(user_id=None, user=None, target=None, connector=None, raw_event=None, raw_parses=None, event_id=None, linked_event=None)

module:

opsdroid.events

A generic event type.

Initiates an Event object with the most basic information about its creation.

type user_id:
param user_id:

String id of user sending message

type user_id:

string, optional

type user:
param user:

String name of user sending message

type user:

string, optional

type target:
param target:

String name of the room or chat channel in which message was sent

type target:

Note: For the sake of flexibility, Opsdroid only supports a single user on any given event. If you use Slack’s (or any other chat platforms supported by Opsdroid that have the possibility of a single event corresponding to multiple users) API call to invite users to a channel, the API call takes a list of users as the input. In that case, you need to create multiple ‘single-user’ events instead of trying to create one ‘multi-user’ event. If concerned about the performance, the Skill can call the API directly rather than emitting multiple events.

OpsdroidStarted

The OpsdroidStarted event is triggered once Opsdroid’s loader has completed. Skills can respond to this in order to perform startup actions which require connectors, databases, etc. to be available first.

… py:class:: OpsdroidStarted(user_id=None, user=None, target=None, connector=None, raw_event=None, raw_parses=None, event_id=None, linked_event=None)

module:

opsdroid.events

An event to indicate that Opsdroid has loaded.

… py:method:: OpsdroidStarted.get_entity(name)

module:

opsdroid.events

Get the value of an entity by name.

type name:
param name:

Name of entity

type name:

string

returns:

The value of the entity. Returns None if no such entity.

… py:method:: OpsdroidStarted.respond(event)

module:

opsdroid.events

async:

Respond to this event with another event.

This implies no link between the event we are responding with and this event.

… py:method:: OpsdroidStarted.update_entity(name, value, confidence=None)

module:

opsdroid.events

Add or update an entitiy.

Adds or updates an entitiy entry for an event.

type name:

Message

The Message object is the most common event type, it represents textual events, and has the following attributes in addition to the base Event attributes.

… py:class:: Message(text, *args, **kwargs)

module:

opsdroid.events

A message object.

Stores messages in a format that allows OpsDroid to respond or react with delays for thinking and typing as defined in configuration YAML file.

type text:
param text:

String text of message

type text:

string

param target:

String name of the room or chat channel in which message was sent

type target:

string, optional

param connector:

Connector object used to interact with given chat service

type connector:

Connector, optional

param raw_event:

Raw message as provided by chat service. None by default

type raw_event:

Typing

An event to represent a typing indication.

… py:class:: Typing(trigger, timeout=None, *args, **kwargs)

module:

opsdroid.events

An event to set the user typing.

type trigger:
param trigger:

Trigger typing on or off.

type trigger:

bool

type timeout:
param timeout:

Timeout on typing event.

type timeout:

float, optional

… py:method:: Typing.get_entity(name)

module:

opsdroid.events

Get the value of an entity by name.

type name:
param name:

Reaction

A reaction to a message, normally an emoji or a string representing one.

… py:class:: Reaction(emoji, *args, **kwargs)

module:

opsdroid.events

Event class to support Unicode reaction to an event.

type emoji:
param emoji:

The emoji to react with.

type emoji:

string

param target:

The room in which the reaction should be sent.

type target:

string, optional

param linked_event:

The event to react to.

type linked_event:

opsdroid.events.Event

… py:method:: Reaction.get_entity(name)

module:

opsdroid.events

Get the value of an entity by name.

type name:

File

A file event. All files should be representable as bytes. A File can be constructed using either a url or a bytes object, if a url is specified the File.file_bytes property will retrieve the url and store the response as bytes.

… py:class:: File(file_bytes=None, url=None, url_headers=None, name=None, mimetype=None, *args, **kwargs)

module:

opsdroid.events

Event class to represent arbitrary files as bytes.

… py:method:: File.get_entity(name)

module:

opsdroid.events

Get the value of an entity by name.

type name:
param name:

Name of entity

type name:

string

returns:

The value of the entity. Returns None if no such entity.

… py:method:: File.get_file_bytes()

module:

opsdroid.events

async:

Return the bytes representation of this file.

… py:method:: File.get_mimetype()

module:

opsdroid.events

async:

Image

The Image event is a subclass of File, so in the same way File can an Image can be either a url or bytes, but should always be representable as bytes.

… py:class:: Image(file_bytes=None, url=None, url_headers=None, name=None, mimetype=None, *args, **kwargs)

module:

opsdroid.events

Event class specifically for image files.

… py:method:: Image.get_dimensions()

module:

opsdroid.events

async:

Return the image dimensions (w,h).

… py:method:: Image.get_entity(name)

module:

opsdroid.events

Get the value of an entity by name.

type name:
param name:

Name of entity

type name:

string

returns:

The value of the entity. Returns None if no such entity.

… py:method:: Image.get_file_bytes()

module:

opsdroid.events

async:

Video

The Video event is a subclass of File, so in the same way File can an Video can be either a url or bytes, but should always be representable as bytes.

… py:class:: Video(file_bytes=None, url=None, url_headers=None, name=None, mimetype=None, *args, **kwargs)

module:

opsdroid.events

Event class specifically for video files.

… py:method:: Video.get_bin()

module:

opsdroid.events

async:

Return the binary representation of video.

… py:method:: Video.get_entity(name)

module:

opsdroid.events

Get the value of an entity by name.

type name:
param name:

Name of entity

type name:

string

returns:

The value of the entity. Returns None if no such entity.

… py:method:: Video.get_file_bytes()

module:

opsdroid.events

async: