Custom Commands

A quick introduction to implementing your own workflows with custom commands.

Introduction to Commands

Text Commands

A text command simply responds to the user immediately with a text that you have predefined in the command configuration. These kind of commands are useful for having frequent text, links or information that your team needs to access on a recurring basis.

For example: you can create a text command named "manifesto" that responds with a text description of what your company manifesto is. Users will be able to use that command in channels or from private conversations with DailyBot.

HTTP Commands

The HTTP Commands let you process a DailyBot command with an app (endpoint) of your own creation, and then respond with dynamic information. This is very powerful and useful for many use cases.

For example: you can create an HTTP command named "sales report" and implement your logic to return the key metrics, so users can access this information in a simple way just using DailyBot, from their own chat app (desktop or mobile).

You can even use HTTP commands for ChatOps: implementing custom workflows and operations of your company that run entirely on the chat. More examples include: deploying an app, getting the version of an app, showing analytics, seeing a repository active branches, etc.

Implementing your custom command

HTTPS and POST method

Your endpoint implementation must be HTTPS (mandatory) and it should receive the data via POST request. Once a command is processed, DailyBot delivers a payload to your endpoint, including special HTTP headers.

Headers
X-DailyBot-Signature: String

The X-DailyBot-Signature header will include your Command signature. You can get the signature by opening your command (in the web app, edit mode) and then clicking the "view signature" link.

Recommendation: use the signature header in your endpoint to validate that the request is authentic.

Payload example (request body)
{
 intent: 'your_command_intent_name',
 event_timestamp: 1620847161125,
 organization_uuid: 'd470abcd-b311-4f4d-81a8-2ca290845432',
 user_uuid: '0024dg21-1c12-4d31-a31f-95e26f675432',
 user_full_name: 'John Doe',
 is_channel_message: false,
 channel: 'XDSZ1232',
 params: { query: '' }
}

The payload will include basic information for you to identify the user and the DailyBot workspace. It also details whether the message is coming from a public channel (when is_channel_message is TRUE).

Implementing complex logic with the "params.query"

Notice you can build your command to implement more complex logic, using the params.query object.

When users use the command, they can include more words or numbers after the command invocation (separated with one space).

Example:

  • Your command name is "sales report"
  • If a user types "sales report 7" — you will get a params:{query:"7"}
  • If a user types" "sales report from last week" — you will get a params:{query:"from last week"}

That means that only one Command in DailyBot can be the entry point to a very complex utility that you develop.

Recommendation:

If you are building a complex logic and your command will support several parameters, consider adding a "help" keyword to give instructions to the users about how to use the command logic.

Example:

  • User types "sales report help" — your command responds with details about usage

Responding to the command

You should process the request in a synchronous way and the response to the command should be either valid JSON or Text. If you use JSON, you can optionally specify the field of that JSON that DailyBot should fetch. Use the "JSON Response Param" for that purpose, from the Command edit page.

Your endpoint should process the request and respond to DailyBot in less than 10 seconds.

If you have a use case where you need to respond asynchronously because the 10 seconds are not enough, please contact our support team. This option is available but is not currently open to all the developers.

Example

We created a CodeSandbox project where you can see a Command implementation example in NodeJS.

https://codesandbox.io/s/dailybot-sample-command-demo-6nu1u

You can use CodeSandbox to clone the project (fork) and play with it yourself.

Need support?
Contact us