How to create a call me form with Laravel to send lead to Vicidial

Let's create a simple form to capture leads in PHP and send them to Vicidial using:

- Laravel (PHP framework)

- Composer (PHP package manager)

- Vicidial (One of the best call contact center software in the world)

Prerequisites

  • php installed (version 8+)

  • composer installed (version 2.5+)

  • Vicidial installed or vicidial server

Create a new Larevel project

To create a new Laravel project, we will use the Laravel CLI

laravel new call-me-form

This will take a while, but the final output should be something like this:

Now step into the project folder:

cd call-me-form

In the terminal, run the following command:

php artisan serve

And you should see something like this:

We will need a package to connect Laravel and vicidial, and for this, we will use masterfermin02/vicidial-api-wrapper:

composer require masterfermin02/vicidial-api-wrapper

Now we are ready to start coding.

Code the application

There are two steps to code the application:

  • Config the Vicidial API connection.

  • Create the web form on our Laravel app.

Vicidial configuration

We recommend creating an API user only on the Vicidial server:

The user must have access to modify the list:

Now we need to update our .env file with the Vicidial config.

VICIDIAL_IP={your_vicidal_server_ip}
VICIDIAL_USER={your_vicidial_user}
VICIDIAL_PASS={your_vicidial_pass}

Replace the information between {} with your Vicidial data.

Creating the Vicidial web form

First, we will need to create a Vicidial controller:

php artisan make:controller Vicidial/Admin/LeadController

Now we need to map our controller on the route open this file:

routes/web.php

And add this code:

Route::get('/', [\App\Http\Controllers\Vicidial\Admin\LeadController::class, 'index'])->name('home');
Route::post('/vicidial/admin/lead', [\App\Http\Controllers\Vicidial\Admin\LeadController::class, 'store'])->name('lead.store');

Go to your controller and add this code:

<?php

namespace App\Http\Controllers\Vicidial\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\View\View;
use Vicidial\Api\Wrapper\Admin\Client;

class LeadController extends Controller
{
    public function index(): View
    {
        return view('pages.vicidial.admin.lead');
    }

    public function store(Request $request): View
    {
        $vicidial = new Client(
            env('VICIDIAL_IP'),
            env('VICIDIAL_USER'),
            env('VICIDIAL_PASS'),
            source:'test',
        hasSSl: false
        );
        $data = $request->all();
        $vicidial->add_lead([
            'first_name' => $data['first-name'],
            'last_name' => $data['last-name'],
            'email' => $data['email'],
            'country' => $data['country'],
            'address1' => $data['street-address'],
            'city' => $data['city'],
            'state' => $data['region'],
            'postal_code' => $data['postal-code'],
            'phone_number' => $data['phone_number'],
        ]);

        return view('pages.vicidial.admin.success');
    }
}

The index method will be called when the user goes to this URL `/` we will need to create this view `pages.vicidial.admin.lead` on the resources folder:

  • Create pages, vicidial, and admin folders.

  • Create a file named lead.blade.php

Open this gist to see the HTML you must use in lead.blade.php:

Gist

Go to your browser `/`, and you should be able to see the following:

Now fill on the information, click on save, and then you should be able to see the lead on Vicidial on list 999 by default. If you want to store it on another list, you must specify.

You can download the full version of this code from the GitHub repository:

https://github.com/masterfermin02/callme-example-for-vicidial

Conclusion

In this post, we learn how to create a Laravel app, create a controller and its route, configure the Vicidial API user only, and use the vicidial-api-wrapper to send leads to a Vicidial server.