If your application cannot establish a Websocket connection to the Engagement API, there is an alternative approach available. You can configure an HTTP URL as a webhook, which will be used by the Engagement API to send all asynchronous events generated during a conversation. When using this option, all asynchronous events will be sent as a POST request to request to the specified URL. The request body will be aJSON with two fields 'type' and 'payload'.

The event types include chat:ready, incoming:msg, incoming:notice, and chat:ended.

The payload content is identical to the events sent through the WebSocket connection. This option will only send events via the HTTP webhook, and the WebSocket will not be utilized.

Note: We expect that the response to every request to the webhook URL to be HTTP 200, if we don't get this response the request will be retried at most 2 more times.

There are two ways to set up this webhook:

1. Add header to Create User POST

Add a valid URL to the X-Pypestream-Webhook-URL header in the Create User POST request.

2. Set the webhook_url on the Pypestream UI App for the Microapp

Set the webhook_url field for this Microapp's Pypestream UI App (coming soon) to a valid URL.

Final Notes

If both the webhook_url field for the Microapp's Pypestream UI App (coming soon) is set and valid, and the X-Pypestream-Webhook-URL header is sent and valid, the header value will be used as the webhook.

If the X-Pypestream-Webhook-URL header value is not a valid URL or is not set, the system will attempt to use the webhook_url field from the Microapp's Pypestream UI App (coming soon). If this field is not set or is not a valid URL, the system will default to using WebSocket to send all events throughout the chat session.