|
1 | 1 | # Websockets
|
2 | 2 |
|
3 |
| -To be continued... |
| 3 | +## Astro Websocket Gateway |
| 4 | + |
| 5 | +Astro is StreamElements' dedicated websocket gateway. It employs a publish-subscribe (pubsub) pattern to facilitate real-time data updates. |
| 6 | + |
| 7 | +To establish a WebSocket connection, clients should connect to: `wss://astro.streamelements.com` |
| 8 | + |
| 9 | +### Client-to-Server Request |
| 10 | + |
| 11 | +The following parameters are used in a client-to-server request: |
| 12 | + |
| 13 | +| Parameter | Type | Description | |
| 14 | +| --- | --- | --- | |
| 15 | +| `type` | `string` | Defines the type of request. Valid options are `subscribe` and `unsubscribe`. | |
| 16 | +| `nonce` | `string` | A unique identifier for the request. Useful for identifying the corresponding response (Optional). | |
| 17 | +| `data.topic` | `string` | The topic to which the client wishes to subscribe. | |
| 18 | +| `data.token` | `string` | The token used to authenticate the request. | |
| 19 | +| `data.token_type` | `string` | Specifies the type of token. Valid options are `apikey` and `jwt`. | |
| 20 | + |
| 21 | +Here is an example of a client-to-server request: |
| 22 | + |
| 23 | +```json |
| 24 | +{ |
| 25 | + "type": "subscribe", |
| 26 | + "nonce": "86ccb2b3-eb8d-4b3c-902d-509c3f5ca88c", |
| 27 | + "data": { |
| 28 | + "topic": "channel.follow", |
| 29 | + "token": "test_token", |
| 30 | + "token_type": "jwt" |
| 31 | + } |
| 32 | +} |
| 33 | +``` |
| 34 | + |
| 35 | +### Server-to-Client Response |
| 36 | + |
| 37 | +The following parameters are used in a server-to-client response: |
| 38 | + |
| 39 | +| Parameter | Type | Description | |
| 40 | +| --- | --- | --- | |
| 41 | +| `id` | `string` | The unique identifier of the response. | |
| 42 | +| `type` | `string` | Defines the type of response. The only valid option is `RESPONSE`. | |
| 43 | +| `nonce` | `string` | The nonce of the original request. | |
| 44 | +| `error` | `string` | The error code, if any. | |
| 45 | +| `data` | `object` | The data contained in the response. | |
| 46 | + |
| 47 | +Here is an example of a server-to-client response: |
| 48 | + |
| 49 | +```json |
| 50 | +{ |
| 51 | + "id": "01HB0YE5TR26EH71DVPJ68MA82", |
| 52 | + "ts": "2023-09-20T16:43:21Z", |
| 53 | + "type": "response", |
| 54 | + "nonce": "86ccb2b3-eb8d-4b3c-902d-509c3f5ca88c", |
| 55 | + "data": "successfully subscribed to topic" |
| 56 | +} |
| 57 | +``` |
| 58 | + |
| 59 | +### Server Notifications |
| 60 | + |
| 61 | +Clients can receive notifications from the server. Here is an example: |
| 62 | + |
| 63 | +```json |
| 64 | +{ |
| 65 | + "id": "01HB0YF39XF16HMHCPDYZYJYFK", |
| 66 | + "ts": "2023-09-23T12:06:25Z", |
| 67 | + "type": "message", |
| 68 | + "topic": "astro", |
| 69 | + "data": { |
| 70 | + "message":"Hello world!" |
| 71 | + } |
| 72 | +} |
| 73 | +``` |
| 74 | + |
| 75 | +### Error Codes |
| 76 | + |
| 77 | +The following error codes may be returned in a server-to-client response: |
| 78 | + |
| 79 | +| Error | Description | |
| 80 | +| --- | --- | |
| 81 | +| `err_internal_error` | An internal error occurred. | |
| 82 | +| `err_bad_request` | The request was malformed or invalid. | |
| 83 | +| `err_unauthorized` | The request lacked valid authentication credentials. | |
| 84 | +| `rate_limit_exceeded` | The rate limit for the API has been exceeded. | |
| 85 | +| `invalid_message` | The message was invalid or could not be processed. | |
| 86 | + |
| 87 | +Here is an example of a server-to-client response containing an error: |
| 88 | + |
| 89 | +```json |
| 90 | +{ |
| 91 | + "id": "01HB0YE5Y88FXMXXCN4ME7M8A1", |
| 92 | + "ts": "2023-09-20T16:43:21Z", |
| 93 | + "type": "response", |
| 94 | + "nonce": "86ccb2b3-eb8d-4b3c-902d-509c3f5ca88c", |
| 95 | + "error": "err_unauthorized", |
| 96 | + "data": { |
| 97 | + "message": "invalid token" |
| 98 | + } |
| 99 | +} |
| 100 | +``` |
| 101 | + |
| 102 | +### Topics |
| 103 | + |
| 104 | +Information on available topics will be released in the near future. |
| 105 | + |
| 106 | +<!-- | Topic | Required Scope | You are notified when | |
| 107 | +| --- | --- | --- | |
| 108 | +| `chatbot.timeout` | `bot:read` | When the chatbot times someone out | --> |
| 109 | + |
0 commit comments