Custom Commands Webhook
Confused about "Custom Commands Webhook"?
Let us know how we can improve our documentation:
Stream supports several slash commands out of the box:
- /giphy query
- /ban @userid reason
- /unban @userid
- /mute @userid
- /unmute @userid
Additionally, it’s possible to add your own commands.
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:
Registering your Custom Command
Configure a Channel Type
Configuring a Custom Action Handler URL
Implement a handler for your Custom Command
Registering Custom Commands
Copied!Confused about "Registering Custom Commands"?
Let us know how we can improve our documentation:
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!Confused about "Command Fields"?
Let us know how we can improve our documentation:
name | type | description | default | optional |
---|---|---|---|---|
name | string | name of the command | - | ✓ |
description | string | description, shown in commands auto-completion | - | ✓ |
args | string | arguments help text, shown in commands auto-completion | - | ✓ |
set | string | set name used for grouping commands | - | ✓ |
Creating a Command
Copied!Confused about "Creating a Command"?
Let us know how we can improve our documentation:
List Commands
Copied!Confused about "List Commands"?
Let us know how we can improve our documentation:
You can retrieve the list of all commands defined for your application.
Get a Command
Copied!Confused about "Get a Command"?
Let us know how we can improve our documentation:
You can retrieve a custom command definition.
Edit a Command
Copied!Confused about "Edit a Command"?
Let us know how we can improve our documentation:
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!Confused about "Remove a Command"?
Let us know how we can improve our documentation:
You can remove a custom command definition.
Configure a Channel Type
Copied!Confused about "Configure a Channel Type"?
Let us know how we can improve our documentation:
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!Confused about "Configure a Custom Action URL"?
Let us know how we can improve our documentation:
In order to use the defined custom commands, you will first have to set an endpoint URL in the App Settings.
{type}
variable substitution in the URL to pass on the name of the command that was triggered. See Webhooks Overview for more information on URL configurationRequest format
Copied!Confused about "Request format"?
Let us know how we can improve our documentation:
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!Confused about "Response format"?
Let us know how we can improve our documentation:
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!Confused about "Discarding messages"?
Let us know how we can improve our documentation:
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!Confused about "Rewriting messages"?
Let us know how we can improve our documentation:
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:
Performance considerations
Copied!Confused about "Performance considerations"?
Let us know how we can improve our documentation:
Your webhook endpoint will be part of the send message transaction, so you should avoid performing any remote calls or potentially slow operations while processing the request. Stream Chat will give your endpoint 1 second of time to reply. If your endpoint is not available (ie. returns a response with status codes 4xx or 5xx) or takes too long, Stream Chat will continue with the execution and save the message as usual.
To make sure that an outage on the hook does not impact your application, Stream will pause your webhook once it is considered unreachable and it will automatically resume once the webhook is found to be healthy again.
Example code
Copied!Confused about "Example code"?
Let us know how we can improve our documentation:
An example of how to handle incoming Custom Command requests can be found in this repo.