|
3 | 3 |
|
4 | 4 | You can test this template: |
5 | 5 | 1. Clone the project and run `npm install` |
6 | | -2. Navigate to `packages/templates/clients/websocket/python` |
7 | | -3. Install with `npm install` and run test with `npm run test` |
8 | | -4. Go to test folder with `cd test` |
9 | | -5. Install dependencies of the generated client: `pip install -r temp/snapshotTestResult/custom_client_hoppscotch/requirements.txt` |
10 | | -6. Start example script that uses a client library generated by the test: `python example.py` |
| 6 | +1. Navigate to `packages/templates/clients/websocket/python` |
| 7 | +1. Install with `npm install` and run test with `npm run test` |
| 8 | +1. Install dependencies of the generated client: `pip install -r test/temp/snapshotTestResult/custom_client_hoppscotch/requirements.txt` |
| 9 | +1. Start example script that uses a client library generated by the test: `python example.py` |
11 | 10 |
|
12 | 11 | > By default this is testing against Hoppscotch echo service. You can modify `packages/templates/clients/websocket/python/example.py` and change line 7 to `from temp.snapshotTestResult.client_postman.client import PostmanEchoWebSocketClientClient` and line 21 `client = PostmanEchoWebSocketClientClient()` and run `python example.py` again. You will see example still works but agains different API. This is possible as both AsyncAPI documents have the same name of operation for sending messages: `sendEchoMessage` so each client generated has the same API. |
13 | 12 |
|
14 | 13 | ## Client for Slack |
15 | 14 |
|
16 | 15 | To run the Slack Client example, follow the steps above but with 2 exceptions: |
17 | 16 | - Use `example-slack.py` instead of `example.py`. |
18 | | -- You need to pass environment variables with proper authorization details. Your command must look like this: `TICKET={provide secret info} APP_ID={provide id of the slack app} python example-slack.py` |
| 17 | +- You need to pass environment variables with proper authorization details. Your command must look like this: `TICKET={provide secret info} APP_ID={provide id of the slack app} python example-slack.py`. For example: `TICKET=1d967f38-ccff-44f6-adec-9616eec9c4b7 APP_ID=00dfdcccb53a2645dd3f1773fcb10fa7b0a598cf333a990a9db12375ef1865dd python example-slack.py`. |
19 | 18 |
|
20 | | -Instructions on how to create the Slack app and also obtain authorization is described in details in the [Slack AsyncAPI document](../test/__fixtures__/asyncapi-slack-client.yml). |
| 19 | +> Instructions on how to create the Slack app and also obtain authorization is described in details in the [Slack AsyncAPI document](../test/__fixtures__/asyncapi-slack-client.yml). |
| 20 | +
|
| 21 | +You can use our AsyncAPI's credentials to access different set of events produced in AsyncAPI Slack workspace, in the `#generator` channel. |
| 22 | + |
| 23 | +1. Generate an access ticket with an application ID that will enable you to establish a websocket connection. Replace the following bearer token with real token that you can find in `slack-example.md` document added to bookmarks of `#generator` channel in [AsyncAPI Slack workspace](https://www.asyncapi.com/slack-invite): |
| 24 | + ``` |
| 25 | + curl --location --request POST 'https://slack.com/api/apps.connections.open' \ |
| 26 | + --header 'Authorization: Bearer xapp-1-A08NKKBFGBD-8768087393844-b85d0215e33ec13272e523e47d96b602d9dc5e57863e5b2df79d81b999da10bc' |
| 27 | + ``` |
| 28 | +>**Note**: Ensure that you do not expose the real token on GitHub or any other public platform because it will be disabled by Slack. |
| 29 | +
|
| 30 | + Example response with `ticket` and `app_id`: |
| 31 | + ``` |
| 32 | + {"ok":true,"url":"wss:\/\/wss-primary.slack.com\/link\/?ticket=089a0c38-cdec-409f-99fa-0ca24e216ea4&app_id=00dfdcccb53a2645dd3f1773fcb10fa7b0a598cf333a990a9db12375ef1865dd"} |
| 33 | + ``` |
| 34 | +
|
| 35 | + You can take generated `url` and use with CLI websocket client like `websocat` (first remove excape backslashes): |
| 36 | + ``` |
| 37 | + websocat "wss://wss-primary.slack.com/link/?ticket=089a0c38-cdec-409f-99fa-0ca24e216ea4&app_id=00dfdcccb53a2645dd3f1773fcb10fa7b0a598cf333a990a9db12375ef1865dd" |
| 38 | + ``` |
| 39 | +
|
| 40 | + But that is just for testing. The point is to use the generated Python client. |
| 41 | +
|
| 42 | +1. Start the example that uses generated client. Examine events, and modify example as you want: |
| 43 | + ``` |
| 44 | + TICKET=089a0c38-cdec-409f-99fa-0ca24e216ea4 APP_ID=00dfdcccb53a2645dd3f1773fcb10fa7b0a598cf333a990a9db12375ef1865dd python example-slack.py |
| 45 | + ``` |
| 46 | + Successfully established connection will welcome you with below event: |
| 47 | + ``` |
| 48 | + {"type":"hello","num_connections":1,"debug_info":{"host":"applink-3","build_number":118,"approximate_connection_time":18060},"connection_info":{"app_id":"A08NKKBFGBD"}} |
| 49 | + ``` |
| 50 | + If you did not receive it, you probably connect with wrong credentials. Remember that generated `ticket` can be used only once to establish a websocket connection. |
0 commit comments