Skip to content

API : Emitters

Damien BUTY edited this page May 20, 2020 · 1 revision

In most cases, aido interactions are triggered by the users when they type in a slash command or click on a view. However, you might know situations where the server takes the initiative to trigger an interaction, either through a scheduled task or because of some external event.

For these cases, aido provides you with two emitters, which can be used to emit either a Slash (emulating the user typing /somecommand in their Slack client), or an Action (emulating the user clicking on a button or submitting a form).

Methods

These methods are exposed on the aido object.

emitSlash (function) : Emits a Slash with the following parameters :

  • user (String) : The Slack ID of the user (UW0TM8)
  • command (String) : The slash command to emulate
  • text (String) : Any additional text after the slash command
  • transportOptions (Object) : transportOptions.channel (String) : The ID of a channel where the interactino should occur (CXXXXXX) transportOptions.conversationWith (Array) : An array of user Slack IDs. This is used to trigger a multi-party conversation with the indicated users. transportOptions.conversationAs (String) : Can contain bot or user. For a multi-party conversation, indicates if the message should be sent as user (the administrator who installed the app) or bot (the bot user of the application).

emitAction (function) : Emits a Slash with the following parameters :

  • user (String) : The Slack ID of the user (UW0TM8)
  • command (String) : The slash command to emulate
  • action (String) : The action to execute (equivalent to the name attribute of a pressed button, or the action attribute of a submitted form)
  • args (Object) : Any arguments that should be sent to the action method
  • transportOptions (Object) : transportOptions.channel (String) : The ID of a channel where the interactino should occur (CXXXXXX) transportOptions.conversationWith (Array) : An array of user Slack IDs. This is used to trigger a multi-party conversation with the indicated users. transportOptions.conversationAs (String) : Can contain bot or user. For a multi-party conversation, indicates if the message should be sent as user (the administrator who installed the app) or bot (the bot user of the application).

Useful plugins

aido-emitters

This plugin will expose the emitters on the Slash class, so you can use this.emitSlash(...) and this.emitAction(...) in your Slash code.

aido-hook

This plugin creates a /hook HTTP endpoint on your aido server, which can be used to emit a Slash or an Action through a webhook.

aido-cron

This plugin allows you to create recurring or one-off scheduled tasks to emit Slashes or Actions.