Skip to main content

Create a Bot

Tutorial on how to create a bot summoned by a slash command sent as a message in a chat area.

Time: 20 minutes

Vocabulary Note:

A bot is an automation triggered either by a slash command or a survey. Every time a bot is triggered, it executes a routine with various stages. Choose from a variety of routine stage types to give your bots all kinds of tools to gather data and carry out diverse automations.

Company Requirements

The company has a problem: not all employees are regularly connected to the app. But we know that their email notifications are always active. To address this situation, we propose using a bot that will contact the person through an email message whenever a user types /emailbomb along with the recipient's email address in a chat area.

The email will contain a message mentioning the channel in which the person's pressence is required. Additionally, a system message will appear in the channel workspace indicating that the email was sent successfully.

Tutorial Objectives

Pre-Requisites

Access Role

  • Due to the wide range of actions a bot can undertake, it is best if your user profile's access role counts with the admin-*-write permission that grants access to the entire Administrative Panel.

Steps

A. Set Up Basic Bot Settings

I. Go to the Bots section.

bot section
  1. From the Main Menu Bar, press the Administrator button.
  2. In the Administrative Panel, select Bots.
  3. The Bots section opens up.

II. Open the Create Bot settings panel.

bot section
  • Press the + icon to open the Create bot settings panel.

III. Set basic settings.

bot section
  1. Name: Email Bomb
  2. User bot name: email_bomb_bot
  3. Description: Send an automatically generated email to a user.
  4. Access Roles: default
  5. Global: Toggle on.
  6. It's a slash command: Toggle on.
  7. Slash command: emailbomb

IV. Open the routine builder.

bot section
  • At the bottom of the Create bot settings panel, under the Routine Builder tab and press the + Add Routine button to open the Routine builder settings panel.


B. Set First Routine Stage (Send Email)

I. Open Routine Stage settings.

bot section
  • A. From the Routine builder settings panel, press the+ Add Stage button.
  • B. A New stage settings panel opens up.
Attention

Once you set the stage Type in the next step, more fields will open up according to the selected stage type.


II. Set up the stage.

bot section
  1. Code: email_bot
  2. Type: Send email
  3. Subject: Hey! We need to talk with you.
  4. Company Name: Ruanda
  5. Title: Your team is looking for you.
  6. Message A: I hope you're not too busy.
  7. Message B: $JOIN# #Your presence is requested in the #($VALUE#channel|nameDisplay)# channel.
  8. Action: Add a blank space or character since this is a required field.
  9. Code: Add a blank space or character since this is a required field.
  10. Advanced mode: Toggle on the Advanced mode switch in the To field.
  11. To: $VALUE#cmdArgs
  12. Press + Add Stage and go to the following step.
Cotlang Scripting Notes:
  • In the Message B (7) and To (11) fields, we use some Cotlang scripts to gather data from the context, i.e., the contextual data relative to the bot. The data context of the slash command bot we are working with comes from the slash command that is sent as a message in a channel. More specifically, the context is the message itself, any extra arguments added to the slash command (in our case, the email address), and the channel the message was sent in.
  • For example, in Message B, we use $VALUE#channel|nameDisplay command to get the channel name from the channel context. And, to add the result to a string, we use $JOIN# command.
  • In To, $VALUE#cmdArgs retreives data from the command arguments context, in this case, the email address. For example, if I execute the slash command typing /emailbomb jane.doe@ruanda.com, the command argument context would be jane.doe@ruanda.com.

C. Set Second Routine Stage (Send Message)

I. Set up stage.

bot section

After pressing the + Add Stage button, set up the second stage with the following:

  1. Code: message_bot
  2. Type: Send message
  3. Content: 📩 Email sent ✅
  4. Content Type: text/system
  5. User: $VALUE#message|sentBy
  6. Channels: Press the + Add Item button.
  7. Item: $VALUE#channel|_id

II. Complete Routine setup.

bot section
  1. Initial stage: email_bot
  2. Max. iterations: 2
  3. Success: message_bot (Make sure you are on the email_bot tab.)
  4. Press Save. You will be taken back to the Bots section.
note

Each execution of a stage is an iteration. Therefore, you need as many iterations as you have stages. If any stage loops, you will have to count each loop as an iteration.


Expected Result

Now the bot is available on all channels.

If you direct yourself to a channel and type /emailbomb name@example.com, the system will send an email to the indicated address and an automated system message gets generated in the chat area.


bot section

The recipient will receive an email similar to the one below:

bot section