This is an old version of the webhooks documentation. Please see Webhooks Overview page

Overview

Copied!

By using Custom Commands, you can receive all messages sent using a specific slash command, eg. /ticket, in your application. When configured, every slash command message happening in a Stream Chat application will propagate to an endpoint via an HTTP POST request.

Setting up your Custom Command consists of the following steps:

  1. Registering your Custom Command

  2. Configure a Channel Type

  3. Configuring a Custom Action Handler URL

  4. Implement a handler for your Custom Command

Registering Custom Commands

Copied!

The API provides methods to create, list, get, update, and delete Custom Command definitions. These determine which commands are allowed to be used and how they're presented to the user by providing a description of the command.

Command Fields

Copied!
nametypedescriptiondefaultoptional
namestringname of the command-
descriptionstringdescription, shown in commands auto-completion-
argsstringarguments help text, shown in commands auto-completion-
setstringset name used for grouping commands-

Creating a Command

Copied!

Please note that applications have a hard limit of 50 custom commands. If you need more than this please have a look at the Multi-tenant & Teams section.

List Commands

Copied!

You can retrieve the list of all custom commands defined for your application.

Get a Command

Copied!

You can retrieve a custom command definition.

Edit a Command

Copied!

Custom command description, args & set can be changed. Only the fields that must change need to be provided, fields that are not provided to this API will remain unchanged.

Remove a Command

Copied!

You can remove a custom command definition.

You cannot delete a custom command if there are any active channel configurations referencing it explicitly.

Configure a Channel Type

Copied!

In order to be able to use this command in a channel, we’ll need to create, or update an existing, channel type to include the ticket command.

Configure a Custom Action URL

Copied!

In order to use the defined custom commands, you will first have to set an endpoint URL in the App Settings.

You can use a {type} variable substitution in the URL to pass on the name of the command that was triggered.

Webhook Requirements

Copied!

In order to use Custom Commands, the endpoint responding to the request must:

  • Be reachable from public internet, tunneling services like Ngrok are supported
  • Respond with a 200 HTTP code in less than 3 seconds
  • Handle HTTP requests with POST body
  • Able to parse JSON payloads
  • Support HTTP/1.1

While not required, we recommend following these best-practices for production environments:

  • Use HTTPS with a certificate from a trusted authority (eg. Let's Encrypt)
  • Verify the "x-signature" header
  • Support Keep-Alive
  • Be highly available
  • Offload the processing of the message (read, store, and forget)

Verify Requests via X-Signature and X-Api-Key

Copied!

All HTTP requests can be verified as coming from Stream (and not tampered by a 3rd party) by analyzing the signature attached to the request. Every request includes an HTTP header called "x-signature" containing a cryptographic signature of the message. Your webhook endpoint can validate that payload and signature match.

If your application uses more than one API Key, you can use the HTTP Header x-api-key to match the signature to the correct secret. Stream will always use the most recently created API Key to sign payloads.

Request format

Copied!

Your endpoint will receive a POST request with a JSON encoded body containing: message, user and form_data objects. The form_data object will contain values of the interactions initiated by either Attachment or MML actions.

Response format

Copied!

If you intend to make any change to the message, you should return a JSON encoded response with the same message structure. Please note that not all message fields can be changed, the full list of fields that can be modified is available in the rewriting messages section.

Discarding messages

Copied!

Your endpoint can decide to reject the command and return a user message. To do that the endpoint must return a regular message with type set to error.

Rewriting messages

Copied!

You can also decide to modify the message, in that case you return the updated version of the message and it will overwrite the user input.

Interactions can be initiated either using Attachment actions:

Or by using MML formatted messages:

Rewritable message fields

Copied!

Not all message fields can be rewritten by your hook handler, fields such as created_at or updated_at for instance are reserved and can only be set by Stream Chat APIs. Any non custom field that is not listed here will be ignored and not updated on the final message.

  1. text

  2. mml

  3. i18n

  4. show_in_channel

  5. silent

  6. type

  7. attachments

  8. any custom field

Example code

Copied!

An example of how to handle incoming Custom Command requests can be found in this repo here.