Skip to content

Commit 10b79f7

Browse files
zgreathousechristinapeng1twitchard
authored
Christina richard/ts webhooks example (#137)
Co-authored-by: christinapeng1 <[email protected]> Co-authored-by: twitchard <[email protected]>
1 parent 214f413 commit 10b79f7

File tree

11 files changed

+1448
-4
lines changed

11 files changed

+1448
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ This repository contains examples of how to use the [Hume API](https://docs.hume
1212
| [`evi-typescript-example`](/evi-typescript-example/README.md) | Typescript | |
1313
| [`evi-typescript-chat-history-example`](/evi-typescript-chat-history-example/README.md) | Typescript | |
1414
| [`evi-typescript-function-calling`](/evi-typescript-function-calling/README.md) | Typescript | |
15+
| [`evi-typescript-webhooks-example`](/evi-typescript-webhooks-example/README.md) | Typescript | Express |
1516
| [`evi-embed-vue`](/evi-embed-vue/README.md) | Typescript | Vue |
1617
| [`evi-python-example`](/evi-python-example/README.md) | Python | |
1718
| [`evi-python-chat-history-example`](/evi-python-chat-history-example/README.md) | Python | |

evi-python-webhooks-example/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div align="center">
22
<img src="https://storage.googleapis.com/hume-public-logos/hume/hume-banner.png">
3-
<h1>Empathic Voice Interface | Webhook Example</h1>
3+
<h1>Empathic Voice Interface | Python Webhook Example</h1>
44
<p>
55
<strong>Receive and Handle Webhook Events from Hume's Empathic Voice Interface (EVI)</strong>
66
</p>
@@ -10,7 +10,7 @@
1010

1111
**This project demonstrates how to:**
1212

13-
- Set up a FastAPI server to receive webhook events from Hume's Empathic Voice Interface (EVI).
13+
- Set up a basic FastAPI server to receive webhook events from Hume's Empathic Voice Interface (EVI).
1414
- Handle `chat_started` and `chat_ended` webhook events.
1515
- Process events to create workflows, such as generating transcripts or logging session details.
1616

evi-python-webhooks-example/app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ async def hume_webhook_handler(request: Request, event: WebhookEvent):
3838
# Process chat_started event
3939
print(f"Processing chat_started event: {event.dict()}")
4040

41-
# Add additional chat_started processing logic here if needed
41+
# Add additional chat_started processing logic here as needed
4242

4343
elif isinstance(event, WebhookEventChatEnded):
4444
# Process chat_ended event
@@ -47,7 +47,7 @@ async def hume_webhook_handler(request: Request, event: WebhookEvent):
4747
# Fetch Chat events, construct a Chat transcript, and write transcript to a file
4848
await get_chat_transcript(event.chat_id)
4949

50-
# Add additional chat_ended processing logic here if needed
50+
# Add additional chat_ended processing logic here as needed
5151

5252
# Run the Uvicorn server
5353
if __name__ == "__main__":
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
HUME_API_KEY="<YOUR_API_KEY>"
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
dist
12+
dist-ssr
13+
*.local
14+
15+
# Editor directories and files
16+
.vscode/*
17+
!.vscode/extensions.json
18+
.idea
19+
.DS_Store
20+
*.suo
21+
*.ntvs*
22+
*.njsproj
23+
*.sln
24+
*.sw?
25+
26+
# Secrets
27+
.env
28+
.env*.local
29+
30+
# Generated transcripts
31+
transcripts/
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<div align="center">
2+
<img src="https://storage.googleapis.com/hume-public-logos/hume/hume-banner.png">
3+
<h1>Empathic Voice Interface | TypeScript Webhook Example</h1>
4+
<p>
5+
<strong>Receive and Handle Webhook Events from Hume's Empathic Voice Interface (EVI)</strong>
6+
</p>
7+
</div>
8+
9+
## Overview
10+
11+
**This project demonstrates how to:**
12+
13+
- Set up a basic (Node) Express server to receive webhook events from Hume's Empathic Voice Interface (EVI).
14+
- Handle `chat_started` and `chat_ended` webhook events.
15+
- Process events to create workflows, such as generating transcripts or logging session details.
16+
17+
**Key Features:**
18+
19+
- **Webhook integration:** Configurable endpoint to receive real-time events.
20+
- **Event handling:** Parse and process `chat_started` and `chat_ended` events with Python utilities.
21+
- **Extensibility:** A base framework for building advanced workflows triggered by EVI events.
22+
23+
## Prerequisites
24+
25+
To run this project locally, ensure your development environment meets the following requirements:
26+
27+
- [Node.js](https://nodejs.org/en) (`v18.0.0` or higher)
28+
- [pnpm](https://pnpm.io/installation) (`v8.0.0` or higher)
29+
30+
To check the versions of `pnpm` and `Node.js` installed on a Mac via the terminal, you can use the following commands:
31+
32+
1. **For Node.js**, enter the following command and press Enter:
33+
34+
```bash
35+
node -v
36+
```
37+
38+
This command will display the version of Node.js currently installed on your system, for example, `v21.6.1`.
39+
40+
2. **For pnpm**, type the following command and press Enter:
41+
42+
```bash
43+
pnpm -v
44+
```
45+
46+
This command will show the version of `pnpm` that is installed, like `8.10.0`.
47+
48+
If you haven't installed these tools yet, running these commands will result in a message indicating that the command was not found. In that case, you would need to install them first. Node.js can be installed from its official website or via a package manager like Homebrew, and `pnpm` can be installed via npm (which comes with Node.js) by running `npm install -g pnpm` in the terminal.
49+
50+
## Setup
51+
52+
### Setting up credentials
53+
54+
- **Obtain Your API Key**: Follow the instructions in the [Hume documentation](https://dev.hume.ai/docs/introduction/api-key) to acquire your API key.
55+
- **Create a `.env` File**: In the project's root directory, create a `.env` file if it doesn't exist. Add your API key:
56+
57+
```sh
58+
HUME_API_KEY="<YOUR_API_KEY>"
59+
```
60+
61+
Refer to `.env.example` as a template.
62+
63+
### Install dependencies
64+
65+
Install the required dependencies with pnpm: `pnpm install`
66+
67+
## Usage
68+
69+
### Running the server
70+
71+
Start the Express server by running the `main.ts` file:
72+
73+
`pnpm start`
74+
75+
### Testing the webhook
76+
77+
Use [ngrok](https://ngrok.com/) or a similar tool to expose your local server to the internet:
78+
79+
`ngrok http 5000`
80+
81+
Copy the public URL generated by ngrok and update your webhook configuration in the Hume **Config**:
82+
83+
- **Webhook URL**: `<NGROK_PUBLIC_URL>/hume-webhook`
84+
- **Events**: Subscribe to `chat_started` and `chat_ended`.
85+
86+
## How It Works
87+
88+
1. **Webhook Endpoint**: The Express server listens for POST requests at `/hume-webhook`.
89+
2. **Event Processing**:
90+
- `chat_started`: Logs session details or triggers workflows.
91+
- `chat_ended`: Processes chat data to generate transcripts or perform analytics.
92+
3. **Custom Logic**: Extend the event handler functions in `main.ts` to integrate with your systems.
93+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "hume-evi-typescript-sample-project",
3+
"private": true,
4+
"version": "0.0.0",
5+
"scripts": {
6+
"start": "ts-node src/main.ts"
7+
},
8+
"dependencies": {
9+
"@types/dotenv": "^8.2.3",
10+
"dotenv": "^16.4.7",
11+
"express": "^4.21.2",
12+
"hume": "^0.9.10"
13+
},
14+
"devDependencies": {
15+
"@types/express": "^5.0.0",
16+
"@types/node": "^22.10.5",
17+
"ts-node": "^10.9.2",
18+
"typescript": "^5.2.2"
19+
},
20+
"engines": {
21+
"node": ">=18"
22+
}
23+
}

0 commit comments

Comments
 (0)