-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathoutbound.ts
More file actions
36 lines (34 loc) · 1.06 KB
/
outbound.ts
File metadata and controls
36 lines (34 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import axios from 'axios'; // Make sure to install axios if not already installed
import { Request, Response } from 'express';
import { envConfig } from '../config/env.config';
export const outboundHandler = async (req: Request, res: Response) => {
// Extract phoneNumberId, assistantId, and customerNumber from the request body
const { phoneNumberId, assistantId, customerNumber } = req.body;
try {
/**!SECTION
* Handle Outbound Call logic here.
* This can initiate an outbound call to a customer's phonenumber using Vapi.
*/
const response = await axios.post(
`${envConfig.vapi.baseUrl}/call/phone`,
{
phoneNumberId: phoneNumberId,
assistantId: assistantId,
customer: {
number: customerNumber,
},
},
{
headers: {
Authorization: `Bearer ${envConfig.vapi.apiKey}`,
},
}
);
res.status(200).json(response.data);
} catch (error) {
res.status(500).json({
message: 'Failed to place outbound call',
error: error.message,
});
}
};