Skip to content

Commit 12182bb

Browse files
Handle Function Call Result and show it in the UI
1 parent daa3083 commit 12182bb

File tree

6 files changed

+54
-24
lines changed

6 files changed

+54
-24
lines changed

README.md

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,37 @@
1-
# React + TypeScript + Vite
1+
# Vapi Integration Starter Template
22

3-
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
3+
This starter template is designed to help you quickly integrate Vapi into your project. It showcases a bot that assists authors in defining characters for their stories, demonstrating the ease of integrating Vapi to manipulate the frontend, display backend results, and leverage other capabilities.
44

5-
Currently, two official plugins are available:
5+
## Features
66

7-
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
8-
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
7+
- **Real-time Interaction**: Interact with the bot in real-time to refine character traits and details.
8+
- **Message Handling**: Send and receive messages to and from the bot, handling different message types.
9+
- **Audio Level Visualization**: Visual feedback on the audio level during bot interaction.
10+
- **Event Handling**: Start, stop, and toggle bot calls with proper event management.
911

10-
## Expanding the ESLint configuration
12+
## Getting Started
1113

12-
If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:
14+
1. Clone the repository.
15+
2. Install dependencies with `npm install`.
16+
3. Set up your `.env` file with the required Vapi tokens.
17+
4. Run the development server with `npm run dev`.
1318

14-
- Configure the top-level `parserOptions` property like this:
19+
## Integration Points
1520

16-
```js
17-
export default {
18-
// other rules...
19-
parserOptions: {
20-
ecmaVersion: 'latest',
21-
sourceType: 'module',
22-
project: ['./tsconfig.json', './tsconfig.node.json'],
23-
tsconfigRootDir: __dirname,
24-
},
25-
}
26-
```
21+
- **Vapi SDK**: Integrated via `vapi.sdk.ts` to manage the Vapi instance.
22+
- **React Hooks**: `useVapi.ts` to encapsulate Vapi logic within React components.
23+
- **Event Listeners**: Set up listeners for various Vapi events like speech start/end, call start/end, and message updates.
24+
- **Message Components**: Render messages and transcripts in real-time as they are received from the bot.
25+
- **Character Details**: Edit and save character details, which are then sent as messages to the bot for processing.
2726

28-
- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked`
29-
- Optionally add `plugin:@typescript-eslint/stylistic-type-checked`
30-
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list
27+
## Project Structure
28+
29+
- `src/`: Source files for the application.
30+
- `src/features/Assistant/`: Components and hooks related to Vapi integration.
31+
- `src/features/Character/`: Components for character details and manipulation.
32+
- `src/lib/`: Shared types and utility functions.
33+
- `src/components/ui/`: Reusable UI components.
34+
35+
## Customization
36+
37+
You can customize the bot's behavior and appearance by modifying the `character.assistant.ts` and the corresponding React components.

src/assistants/character.assistant.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export const characterAssistant: CreateAssistantDTO = {
5959
inspiration: {
6060
type: "string",
6161
description:
62-
"Based on the user query, this defines the inspiration that the author is looking for. It could be some kind of similarity or something else as well.",
62+
"Based on the user query, this defines the inspiration that the author is looking for. It could be some kind of similarity or something else as well. It should be detailed.",
6363
},
6464
},
6565
},

src/features/Character/CharacterPreview.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ function CharacterPreview() {
44
return (
55
<div>
66
<div className="border rounded-lg p-4 flex flex-col gap-2 w-96 m-3 h-auto">
7-
<h1 className="text-2xl text-center w-full">Preview</h1>
7+
<h1 className="text-2xl text-center w-full">Character Designer</h1>
88
<CharacterDetails />
99
</div>
1010
</div>

src/features/Messages/FunctionCallMessage.tsx

Whitespace-only changes.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { FunctionCallResultMessage } from "../../lib/types/conversation.type";
2+
3+
interface FunctionCallResultMessageProps {
4+
message: FunctionCallResultMessage;
5+
}
6+
7+
export default function FunctionCallResult({
8+
message,
9+
}: FunctionCallResultMessageProps) {
10+
return (
11+
<div
12+
className={`flex w-4/5 text-sm mb-4 justify-end text-[#1a0400] font-medium mx-auto`}
13+
>
14+
<div className={`p-3 rounded-xl bg-green-100 mx-auto`}>
15+
<p className="leading-relaxed">{message.functionCallResult.result}</p>
16+
</div>
17+
</div>
18+
);
19+
}

src/features/Messages/MessageList.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ import {
44
TranscriptMessage,
55
} from "@/lib/types/conversation.type";
66
import { ConversationMessage } from "./ConversationMessage";
7+
import FunctionCallResult from "./FunctionCallResult";
78

89
interface MessageListProps {
910
messages: Message[];
1011
activeTranscript?: TranscriptMessage | null;
1112
}
1213

1314
export function MessageList({ messages, activeTranscript }: MessageListProps) {
15+
console.log("messages", messages);
1416
return (
1517
<>
1618
{messages.map((message, index) =>
@@ -19,6 +21,8 @@ export function MessageList({ messages, activeTranscript }: MessageListProps) {
1921
message={message}
2022
key={message.type + message?.role + index}
2123
/>
24+
) : message.type === MessageTypeEnum.FUNCTION_CALL_RESULT ? (
25+
<FunctionCallResult key={message.type + index} message={message} />
2226
) : null
2327
)}
2428
{activeTranscript ? (

0 commit comments

Comments
 (0)