Skip to content

Commit bf5cb8d

Browse files
authored
docs: update slack example with real token (#1624)
Co-authored-by: Lukasz Gornicki <lpgornicki@gmail.com>
1 parent d935cf0 commit bf5cb8d

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

packages/templates/clients/websocket/python/README.md

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,48 @@
33

44
You can test this template:
55
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`
1110

1211
> 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.
1312
1413
## Client for Slack
1514

1615
To run the Slack Client example, follow the steps above but with 2 exceptions:
1716
- 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`.
1918

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.

packages/templates/clients/websocket/python/example-slack.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
sys.path.append(os.path.join(os.path.dirname(__file__), 'test'))
66

7-
from temp.snapshotTestResult.client_slack.client import SlackWebsocketAPIClientClient
7+
from temp.snapshotTestResult.client_slack.client import SlackWebsocketAPIClient
88

99
def custom_message_handler(message):
1010
print(f"\033[94mIncomming event from Slack\033[0m: {message}")
1111

1212
def main():
13-
client = SlackWebsocketAPIClientClient()
13+
client = SlackWebsocketAPIClient()
1414
client.register_message_handler(custom_message_handler)
1515

1616
client.connect()

0 commit comments

Comments
 (0)