File size: 9,019 Bytes
2abc620
 
 
 
52ab21e
2abc620
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
360e8b3
2abc620
360e8b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c33dbd0
360e8b3
 
 
 
 
 
 
 
c33dbd0
 
 
360e8b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fa064b6
c33dbd0
5c54434
 
c33dbd0
 
 
fa064b6
 
 
 
 
360e8b3
 
 
2abc620
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fa064b6
2abc620
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52ab21e
 
2abc620
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fa064b6
2abc620
 
 
fa064b6
 
2abc620
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fa064b6
 
 
 
 
 
 
 
 
 
2abc620
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
# vBot FreePBX Setup Guide

## Overview

This guide provides detailed instructions for setting up FreePBX to work with vBot. FreePBX will handle call recording and webhook integration, while vBot processes the recordings and returns analysis results. All call records are stored locally in the FreePBX database.

## Prerequisites

- FreePBX 16 or higher
- MySQL 5.7 or higher (included with FreePBX)
- PHP 7.4 or higher (included with FreePBX)
- SSL certificate for secure webhooks
- vBot API key (provided by central server admin)

## Step 1: FreePBX Installation

1. Download FreePBX:
   - Visit https://www.freepbx.org/downloads/
   - Download FreePBX 16 or higher
   - Follow the installation guide

2. Complete FreePBX Setup:
   - Run the setup wizard
   - Configure basic settings
   - Set up admin credentials
   - Configure network settings

3. Verify Installation:
   ```bash
   # Check FreePBX version
   sudo asterisk -rx "core show version"
   
   # Check MySQL version
   mysql --version
   
   # Check PHP version
   php -v
   ```

## Step 2: FreePBX Configuration

1. Configure Call Recording:
   - Log in to FreePBX Admin
   - Go to Admin β†’ Call Recording
   - Enable call recording
   - Set recording path: `/var/spool/asterisk/monitor`
   - Configure recording format: WAV
   - Set recording options

2. Set Up Recording Post-Processing:
   - Log in to FreePBX Admin
   - Go to Admin β†’ Advanced Settings
   - Navigate to "System Recordings" section
   - Enable "Post Call Recording Script"
   - Set the script path: `/var/lib/asterisk/agi-bin/process_call`
   - Configure script parameters:
     ```
     ${UNIQUEID} ${CALLERID(num)} ${EXTEN}
     ```
   - Set execution permissions:
     ```bash
     sudo chmod +x /var/lib/asterisk/agi-bin/process_call
     sudo chown asterisk:asterisk /var/lib/asterisk/agi-bin/process_call
     ```
   - Configure recording options:
     - Set recording format to WAV
     - Enable automatic recording
     - Set recording path
     - Configure file naming convention
   - Test recording:
     ```bash
     # Make a test call
     # Check recording directory
     ls -l /var/spool/asterisk/monitor/
     # Verify script execution
     tail -f /var/log/asterisk/messages
     ```

3. Configure Webhook Integration:
   - Go to Admin β†’ Advanced Settings
   - Navigate to "Webhooks" section
   - Add new webhook:
     - Name: vBot Call Processing
     - URL: https://iajitpanday-vbot.hf.space/api/v1/process-call
     - Method: POST
     - Headers:
       ```
       X-API-Key: your_api_key
       Content-Type: multipart/form-data
       ```
     - Payload:
       ```
       file=@${RECORDING_FILE}
       caller_number=${CALLERID(num)}
       called_number=${EXTEN}
       ```
   - Configure webhook triggers:
     - Event: Call Recording Complete
     - Conditions: All calls
   - Set retry policy:
     - Max retries: 3
     - Retry interval: 5 seconds
   - Enable webhook logging:
     ```bash
     sudo nano /etc/asterisk/logger.conf
     # Add:
     [logfiles]
     webhook => notice,warning,error,debug
     ```
   - Test webhook:
     ```bash
     # Test webhook delivery
     curl -X POST https://iajitpanday-vbot.hf.space/api/v1/process-call \
       -H "X-API-Key: your_api_key" \
       -H "Content-Type: multipart/form-data" \
       -F "file=@/var/spool/asterisk/monitor/test.wav" \
       -F "caller_number=+1234567890" \
       -F "called_number=+0987654321"
     
     # Test webhook reception
     curl -X POST https://your-freepbx-domain.com/customer_webhook/webhook.php \
       -H "Content-Type: application/json" \
       -d '{"test": true}'
     ```

4. Configure SSL:
   - Go to Admin β†’ Certificates
   - Generate or upload SSL certificate
   - Configure HTTPS settings
   - Verify SSL configuration

## Step 3: Webhook Integration

1. Install Webhook Package:
   ```bash
   cd /var/www/html
   git clone https://huggingface.co/spaces/iajitpanday/vBot/customer_webhook
   cd customer_webhook
   composer install
   ```

2. Configure Webhook:
   ```bash
   cp config/config.example.php config/config.php
   nano config/config.php
   ```
   ```php
   <?php
   return [
       'db' => [
           'host' => 'localhost',
           'name' => 'vbot_calls',
           'user' => 'vbot_user',
           'pass' => 'your_password'
       ],
       'api_key' => 'your_api_key',
       'api_url' => 'https://iajitpanday-vbot.hf.space',
       'webhook_secret' => 'your_webhook_secret'
   ];
   ```

3. Set Permissions:
   ```bash
   chown -R asterisk:asterisk /var/www/html/customer_webhook
   chmod -R 755 /var/www/html/customer_webhook
   ```

## Step 4: Database Setup

1. Create Database:
   ```sql
   CREATE DATABASE vbot_calls;
   USE vbot_calls;
   
   -- This table stores all call records locally
   -- The central vBot server does not store call records
   CREATE TABLE call_records (
       id VARCHAR(36) PRIMARY KEY,
       customer_id INT NOT NULL,
       caller_number VARCHAR(20) NOT NULL,
       called_number VARCHAR(20) NOT NULL,
       transcription TEXT,
       summary TEXT,
       sentiment VARCHAR(50),
       keywords TEXT,
       created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
       updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
   );
   ```

2. Create Database User:
   ```sql
   CREATE USER 'vbot_user'@'localhost' IDENTIFIED BY 'your_password';
   GRANT ALL PRIVILEGES ON vbot_calls.* TO 'vbot_user'@'localhost';
   FLUSH PRIVILEGES;
   ```

## Step 5: Call Processing Setup

1. Configure Dialplan:
   - Go to Admin β†’ Dialplan
   - Add custom dialplan for call recording
   - Configure post-recording processing

2. Set Up AGI Script:
   ```bash
   nano /var/lib/asterisk/agi-bin/process_call
   ```
   ```bash
   #!/bin/bash
   CALL_ID=$1
   CALLER=$2
   CALLED=$3
   
   curl -X POST https://iajitpanday-vbot.hf.space/api/v1/process-call \
     -H "X-API-Key: your_api_key" \
     -H "Content-Type: multipart/form-data" \
     -F "file=@/var/spool/asterisk/monitor/${CALL_ID}.wav" \
     -F "caller_number=${CALLER}" \
     -F "called_number=${CALLED}"
   ```

3. Set Script Permissions:
   ```bash
   chmod +x /var/lib/asterisk/agi-bin/process_call
   chown asterisk:asterisk /var/lib/asterisk/agi-bin/process_call
   ```

## Step 6: Security Configuration

1. Firewall Setup:
   ```bash
   sudo ufw allow 80/tcp
   sudo ufw allow 443/tcp
   sudo ufw allow 5060/udp  # SIP
   sudo ufw allow 10000:20000/udp  # RTP
   sudo ufw enable
   ```

2. SSL Configuration:
   - Use Let's Encrypt for free SSL certificates
   - Configure automatic renewal
   - Use strong cipher suites

3. File Permissions:
   - Secure webhook handler files
   - Restrict access to call recordings
   - Use appropriate ownership

## Step 7: Testing

1. Test Call Recording:
   ```bash
   # Make a test call
   # Check recording directory
   ls -l /var/spool/asterisk/monitor/
   
   # Check FreePBX logs
   tail -f /var/log/asterisk/messages
   ```

2. Test Webhook:
   ```bash
   # Test webhook delivery
   curl -X POST https://iajitpanday-vbot.hf.space/api/v1/process-call \
     -H "X-API-Key: your_api_key" \
     -H "Content-Type: multipart/form-data" \
     -F "file=@/var/spool/asterisk/monitor/test.wav" \
     -F "caller_number=+1234567890" \
     -F "called_number=+0987654321"
   
   # Test webhook reception
   curl -X POST https://your-freepbx-domain.com/customer_webhook/webhook.php \
     -H "Content-Type: application/json" \
     -d '{"test": true}'
   ```

3. Test Database:
   ```sql
   SELECT * FROM call_records ORDER BY created_at DESC LIMIT 1;
   ```

## Step 8: Monitoring

1. Log Monitoring:
   ```bash
   # FreePBX logs
   tail -f /var/log/asterisk/messages
   
   # Webhook logs
   tail -f /var/log/apache2/vbot-access.log
   
   # Database logs
   tail -f /var/log/mysql/error.log
   ```

2. System Monitoring:
   ```bash
   # Install monitoring tools
   sudo apt install prometheus node-exporter
   
   # Configure monitoring
   sudo nano /etc/prometheus/prometheus.yml
   ```

## Step 9: Maintenance

1. Regular Tasks:
   - Update FreePBX
   - Rotate logs
   - Backup database
   - Clean old recordings

2. Backup Strategy:
   ```bash
   # Database backup
   mysqldump -u vbot_user -p vbot_calls > backup.sql
   
   # Configuration backup
   tar -czf config_backup.tar.gz /etc/asterisk/
   ```

3. Update Process:
   ```bash
   # Update FreePBX
   sudo apt update
   sudo apt upgrade
   
   # Update webhook package
   cd /var/www/html/customer_webhook
   git pull
   ```

## Troubleshooting

1. Common Issues:
   - Call recording failures
   - Webhook delivery problems
   - Database connection errors
   - SSL certificate issues

2. Debug Tools:
   ```bash
   # Check FreePBX CLI
   sudo asterisk -rx "core show version"
   
   # Check webhook logs
   tail -f /var/log/apache2/vbot-error.log
   
   # Test database connection
   mysql -u vbot_user -p vbot_calls
   ```

3. Support:
   - Check FreePBX documentation
   - Review logs
   - Contact support
   - Submit issues