Introduction

This tutorial builds an app that provides a slash command, /reminder, that sends a reminder to everyone in a conversation. The syntax of the command is

/reminder <seconds> <text of the reminder>

The first argument to this command indicates the number of seconds to wait before sending a reminder. The remaining arguments comprise the reminder text.

When the wait time has elapsed, a Message with the reminder text is sent to everyone in the conversation.

Handing App Installs and Tokens

Before proceeding further, please go through Handling App Installs and Tokens, since the current tutorial builds on top of it.

Setup Slash Command

  1. Go to your app's page in the developer dashboard
  2. Click on Advanced information
  3. Enable Slash Command
  4. Provide the following fields:
    1. Name of the commandreminder
    2. Short description
    3. Syntax hint<seconds> <text of the reminder>
    4. Select action: "Send to event listener URL"
  5. Click Save

Next step is to handle the slash command inside the app.

Handling Slash Commands

The slash command event, client.slashCommand, is sent to your event listener URL.

For example, if the user types the slash command /reminder 300 have dinner, the following event (as HTTP request body) is reported to your event listener URL.

{
    "name": "client.slashCommand",
    "userId": "u:xxxxxx",
    "userName": "Alyssa P. Hacker",
    "chat": "g:yyyyyy",
    "chatName": "SICP Hackers",
    "command": "reminder",
    "text": "300 have dinner"
}

For each event that you receive, do verify the event token first (provided in the X-Flock-Event-Token header of the HTTP request).

To distinguish this event from app.install (which we saw in Handling App Installs and Tokens), check the name of the event in the request body.

Upon receiving the slash command, your app should schedule the reminder at the appropriate time. It should acknowledge to the user that it received the slash command by sending a text in response to the HTTP request.

{
    "text": "Received your slash command"
}

For more details on handling slash commands, take a look at Slash Commands.

Sending the Reminder

To send a reminder, you need to send a message to the conversation. Use chat.sendMessage for this; you will need the authentication token that you received during app install.

curl
curl -v -d token=<token> -d to=g:yyyyy -d text='Have dinner' https://api.flock.co/v1/chat.sendMessage

For more details on sending a message, please see: