Skip to content

Commit dbfa4b9

Browse files
authored
feat(phone): Add audio webhook examples. (#323)
1 parent f1fa3f3 commit dbfa4b9

File tree

13 files changed

+1976
-0
lines changed

13 files changed

+1976
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
6+
# Env file for local testing
7+
.env
8+
9+
# Runtime data
10+
pids
11+
*.pid
12+
*.seed
13+
14+
# Directory for instrumented libs generated by jscoverage/JSCover
15+
lib-cov
16+
17+
# Coverage directory used by tools like istanbul
18+
coverage
19+
20+
# nyc test coverage
21+
.nyc_output
22+
23+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24+
.grunt
25+
26+
# node-waf configuration
27+
.lock-wscript
28+
29+
# Compiled binary addons (http://nodejs.org/api/addons.html)
30+
build/Release
31+
32+
# Dependency directories
33+
node_modules
34+
jspm_packages
35+
36+
# Optional npm cache directory
37+
.npm
38+
.npmrc
39+
40+
# IntelliJ/WebStorm Files
41+
.idea
42+
*.iml
43+
44+
# Optional REPL history
45+
.node_repl_history
46+
dist
47+
built
48+
~$*.pptx
49+
.DS_Store
50+
51+
*uploads/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# Audio Webhook
2+
3+
## Introduction
4+
5+
This repo contains code to demonstrate how to process the `audio-webhook` for watsonx Assistant. The `audio-webhook` is a way for developers in watsonx Assistant to specify an endpoint of where to receive the audio recordings for the `record` step in an action in watsonx Assistant.
6+
7+
Here is the representation of the HTTP POST request for the `audio-webhook`
8+
9+
```
10+
POST /audio-webhook HTTP/1.1
11+
Content-Type: multipart/form-data; boundary=----------3676416B-9AD6-440C-B3C8-FC66DDC7DB45
12+
----------3676416B-9AD6-440C-B3C8-FC66DDC7DB45
13+
Content-Disposition: form-data; name="metadata"
14+
Content-Type: application/json
15+
{
16+
"assistant_id": "dadf4b56-3b67-411a-b48d-079806b626d3",
17+
"environment_id": "6205aead-fe91-44af-bfe1-b4435015ba23",
18+
"session_id": "50989a59-9976-4b3f-9a98-af42adcad69a",
19+
"recording_id": "3daeb5d2-f52b-4c3e-a869-328b6fc6327c",
20+
"start_timestamp": "2024-10-21T17:22:07.789Z",
21+
"stop_timestamp": "2024-10-21T17:22:37.789Z"
22+
}
23+
----------3676416B-9AD6-440C-B3C8-FC66DDC7DB45
24+
Content-Disposition: form-data; name="audio_recording"
25+
Content-Type: audio/mulaw;rate=8000
26+
27+
<binary data>
28+
```
29+
30+
## Setup
31+
32+
**Prerequisites**
33+
- Latest [Version of NodeJS](https://nodejs.org/en/about/previous-releases)
34+
35+
Clone the repository:
36+
37+
```
38+
git clone https://github.com/watson-developer-cloud/assistant-toolkit.git
39+
```
40+
41+
### Run the Server Locally
42+
43+
1. Change directory to the `audio-webhook-server`
44+
```
45+
cd assistant-toolkit/integrations/phone/examples/audio-webhook/audio-webhook-server
46+
```
47+
48+
2. Install the dependencies:
49+
50+
```
51+
npm ci
52+
```
53+
54+
3. Run the server
55+
56+
```
57+
npm start
58+
```
59+
60+
4. The server is now running at `http://localhost:8080`. You should see the message:
61+
```
62+
[audio webhook server]: Listening on http://localhost:8080
63+
```
64+
65+
To allow Watson Assistant to access the API server, you need to expose the server to the internet. You can use tools
66+
like [ngrok](https://ngrok.com/) to do that. After installing ngrok, run `ngrok http 8080` to expose the server to the
67+
internet.
68+
69+
#### Configuration
70+
71+
| Configuration | Description |
72+
| --- | --- |
73+
| `UPLOAD_TO_DISK` | Defaults to `false`. Set to `true` to upload the files to disk. |
74+
| `AUDIO_WEBHOOK_SECRET` | Specify the secret you want to use in order to verify the JWT signature from watsonx Assistant or the test client. |
75+
76+
77+
78+
### Run the Test Client
79+
80+
This repository also includes a test client that can be used to test your server implementation without needing to place calls to the watsonx Assistant Phone Integration. This client generates a random GUID for the Assistant ID, Environment ID, recording ID every time a request is made and submits the audio stored in `src/assets/sample.wav`
81+
82+
To run the test client follow these steps:
83+
84+
1. Change directory to `audio-webhook-test-client`
85+
```
86+
cd assistant-toolkit/integrations/phone/examples/audio-webhook/audio-webhook-test-client/
87+
```
88+
89+
2. Install the dependencies
90+
91+
```
92+
npm ci
93+
```
94+
95+
96+
3. Run the client
97+
98+
```
99+
npm start
100+
```
101+
102+
4. In the standard out of your terminal you should see a message and the payload of what was submitted.
103+
```
104+
"Audio Webhook Called Successfully"
105+
```
106+
107+
| Configuration | Description |
108+
| --- | --- |
109+
| `AUDIO_WEBHOOK_URL` | Specify the full URL to send the request to for testing, for example `http://localhost:8080/audiowebhook` |
110+
| `AUDIO_WEBHOOK_SECRET` | Specify the secret you want to use in order to authenticate the client against the Audio Webhook server. |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
UPLOAD_TO_DISK=false
2+
AUDIO_WEBHOOK_SECRET='dummysecret'

0 commit comments

Comments
 (0)