Webhooks¶
Slackchat-serializer will fire webhooks whenever Message
, Reaction
, Attachment
or KeywordArgument
objects are saved or deleted.
Verifying your endpoint¶
Slackchat asks to verify your endpoint before it will send notifications.
To do so, it will send a payload that looks like this:
{
"token": "your-webhook-verification-token",
"type": "url_verification",
"challenge": "a-challenge",
}
You endpoint should sniff the type
and reply back with the challenge.
For example, you could use Django Rest Framework in a view to respond to the challenge like this:
class Webhook(APIView):
def post(self, request, *args, **kwargs):
payload = request.data
if payload.get('token') != WEBHOOK_VERIFICATION_TOKEN:
return Response(status=status.HTTP_403_FORBIDDEN)
if payload.get('type') == 'url_verification':
return Response(
data=payload.get('challenge'),
status=status.HTTP_200_OK
)
# Now handle regular notifications...
Note
If you need to fire a repeat verification request because your endpoint didn’t respond correctly the first time or because the endpoint URL changed, simply open the Webhook
instance in Django’s admin and re-save it.
Update Payload¶
Whenever one of the notification models is updated, the app will send a payload to every verified endpoint with the ID of the channel that was updated, allowing your renderer to hit the channel’s API and republish the updated data.
{
"token": "your-webhook-verification-token",
"type": "update_notification",
"channel": "a-channel-uuid-xxxx...",
"chat_type": "a-chat-type"
}
If the type of the webhook is update_notification
, the payload will also include an update_type
of message_created
, message_changed
, or message deleted
. It will also include a message
key with data about the message that was added, changed, or deleted.
{
"token": "your-webhook-verification-token",
"type": "update_notification",
"channel": "a-channel-uuid-xxxx...",
"chat_type": "a-chat-type"
"update_type": "message_added",
"message": {
"timestamp": "2018-10-16T17:23:49.000100Z",
"user": "USERID",
"content": "A new message."
}
}
Explicit Payloads¶
Users can also use the Django admin or CMS to send endpoints explicit request payloads.
republish_request
¶
A request to publish (or republish) all static assets associated with the channel. It carries with it the channel data as a serialized JSON string.
{
token: "your-webhook-verification-token",
type: "republish_request",
channel: "a-channel-uuid-xxxx...",
channel_data: "{ ... \"title\": \"Channel Title\", \"introduction\": \"Lorem ipsum\", ... }",
chat_type: "a-chat-type"
}
unpublish_request
¶
A request to unpublish (or otherwise remove) all static assets associated with the channel. It carries with it the channel data as a serialized JSON string.
{
token: "your-webhook-verification-token",
type: "unpublish_request",
channel: "a-channel-uuid-xxxx...",
channel_data: "{ ... "title": "Channel Title", "introduction": "Lorem ipsum", ... }",
chat_type: "a-chat-type"
}