0.3.1 • Published 5 months ago

@hamsa-ai/voice-agents-sdk v0.3.1

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

Hamsa Voice Agents Web SDK

Hamsa Voice Agents Web SDK is a JavaScript library for integrating voice agents from https://dashboard.tryhamsa.com. This SDK provides a seamless way to incorporate voice interactions into your web applications.

Installation

Install the SDK via npm:

npm i @hamsa-ai/voice-agents-sdk

Usage

Using via npm

First, import the package in your code:

import { HamsaVoiceAgent } from '@hamsa-ai/voice-agents-sdk'

Initialize the SDK with your API key:

const agent = new HamsaVoiceAgent(API_KEY);

Using via CDN

Include the script from a CDN:

<script src="https://unpkg.com/@hamsa-ai/voice-agents-sdk@LATEST_VERSION/dist/index.umd.js"></script>

Then, you can initialize the agent like this:

const agent = new HamsaVoiceAgent('YOUR_API_KEY');

agent.on("callStarted", () => { console.log("Conversation has started!"); });

// Example: Start a call
// agent.start({ agentId: 'YOUR_AGENT_ID' });

Make sure to replace LATEST_VERSION with the actual latest version number.

Start a Conversation with an Existing Agent

Start a conversation with an existing agent by calling the "start" function. You can create and manage agents in our Dashboard or using our API (see: https://docs.tryhamsa.com):

agent.start({
    agentId: YOUR_AGENT_ID,
    params: {
        param1: "NAME",
        param2: "NAME2"
    }
});

When creating an agent, you can add parameters to your pre-defined values. For example, you can set your Greeting Message to: "Hello {{name}}, how can I help you today?" and pass the "name" as a parameter to use the correct name of the user.

Pause/Resume a Conversation

To pause the conversation, call the "pause" function. This will prevent the SDK from sending or receiving new data until you resume the conversation:

agent.pause();

To resume the conversation:

agent.resume();

End a Conversation

To end a conversation, simply call the "end" function:

agent.end();

Events

During the conversation, the SDK emits events to update your application about the conversation status.

Conversation Status Events

agent.on("callStarted", () => { console.log("Conversation has started!"); });
agent.on("callEnded", () => { console.log("Conversation has ended!"); });
agent.on("callPaused", () => { console.log("The conversation is paused"); });
agent.on("callResumed", () => { console.log("Conversation has resumed"); });

Agent Status Events

agent.on("speaking", () => { console.log("The agent is speaking"); });
agent.on("listening", () => { console.log("The agent is listening"); });

Conversation Script Events

agent.on("transcriptionReceived", (text) => { console.log("User speech transcription received", text); });
agent.on("answerReceived", (text) => { console.log("Agent answer received", text); });

Error Events

agent.on("closed", () => { console.log("Conversation was closed"); });
agent.on("error", (e) => { console.log("Error was received", e); });
0.2.9-beta.2

5 months ago

0.2.0-beta.2

11 months ago

0.2.0-beta.1

11 months ago

0.2.0-beta.6

11 months ago

0.2.0-beta.5

11 months ago

0.2.0-beta.4

11 months ago

0.2.0-beta.3

11 months ago

0.2.0-beta.9

9 months ago

0.3.0

5 months ago

0.2.0-beta.8

9 months ago

0.2.0-beta.7

11 months ago

0.2.0-beta.10

9 months ago

0.2.0-beta.11

9 months ago

0.2.7

7 months ago

0.2.6

7 months ago

0.2.9

5 months ago

0.2.8

5 months ago

0.2.3

8 months ago

0.3.1

5 months ago

0.2.5

8 months ago

0.2.4

8 months ago

0.2.1

12 months ago

0.2.2

12 months ago

0.2.0

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago