|
| 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 | + |
0 commit comments