PHPackages                             zapply/zapply-laravel - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. zapply/zapply-laravel

ActiveLibrary

zapply/zapply-laravel
=====================

Laravel Zapply API Wrapper

1.0.4(2y ago)033MITPHPPHP ^8.2

Since Jan 19Pushed 2y agoCompare

[ Source](https://github.com/zapply-api/zapply-laravel)[ Packagist](https://packagist.org/packages/zapply/zapply-laravel)[ RSS](/packages/zapply-zapply-laravel/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (14)Versions (6)Used By (0)

Zapply for Laravel
==================

[](#zapply-for-laravel)

[![Total Downloads](https://camo.githubusercontent.com/fde283b6a8e8e0d69f3eb589bcc1ecd0991e4b6668c974e2093222c71f6c8438/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7a6170706c792f7a6170706c792d6c61726176656c)](https://packagist.org/packages/zapply/zapply-laravel)[![Latest Stable Version](https://camo.githubusercontent.com/c20ae12e361e201ff4479ad033102ebc81be60875c8fe2bfddbffbc82cf153b3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7a6170706c792f7a6170706c792d6c61726176656c)](https://packagist.org/packages/zapply/zapply-laravel)[![License](https://camo.githubusercontent.com/f00edf801024d7ddaa3bead5730f6047fdc439b3694d88a81fa7f587dd4f6952/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7a6170706c792f7a6170706c792d6c61726176656c)](https://packagist.org/packages/zapply/zapply-laravel)

Getting Started
---------------

[](#getting-started)

First install Zapply for Laravel via the Composer package manager:

```
composer require zapply/zapply-laravel
```

Next, you must load the service provider:

```
// config/app.php
'providers' => [
    // ...
    Zapply\Laravel\ZapplyServiceProvider::class,
],
```

Next, you should configure your application's .env file:

```
ZAPPLY_BASE_URI=your-zapply-base-uri
ZAPPLY_API_KEY=your-zapply-api-key
ZAPPLY_CHANNEL_ID=your-zapply-channel-id
```

Finally, you may use the Resend facade to access Zapply API:

```
use Zapply\Laravel\Facades\Zapply;

Zapply::chat('552199999999')->sendMessage([
    'recipient_type' => 'individual',
    'type' => 'text',
    'message' => [
        'body' => 'Hello World!',
    ]
])
```

Sending via Laravel Notifications
---------------------------------

[](#sending-via-laravel-notifications)

In every model you wish to be notifiable via WhatsApp, you must add a number property to that model accessible through a routeNotificationForZapply method:

```
class User extends Eloquent
{
    use Notifiable;

    public function routeNotificationForZapply()
    {
        return $this->number;
    }
}
```

The number should be in format: Country Code + Area Code + Phone Number, for example: 552199999999.

You may now tell Laravel to send notifications to WhatsApp in the via method:

```
use Illuminate\Notifications\Notification;
use Zapply\Laravel\Zapply;
use Zapply\Laravel\Messages\TextMessage;

class InvoicePaid extends Notification
{
    public function via($notifiable)
    {
        return [Zapply::class];
    }

    public function toZapply($notifiable)
    {
        return TextMessage::create('Your invoice has been paid!');
    }
}
```

### Available Message Types

[](#available-message-types)

```
use Zapply\Laravel\Messages\TextMessage;
use Zapply\Laravel\Messages\ImageMessage;
use Zapply\Laravel\Messages\AudioMessage;
use Zapply\Laravel\Messages\DocumentMessage;
use Zapply\Laravel\Messages\VideoMessage;

TextMessage::create('Hello World!');

ImageMessage::create('https://example.com/image.jpg', 'Caption!');

AudioMessage::create('https://example.com/audio.mp3');

DocumentMessage::create('https://example.com/document.pdf', 'Caption!');

VideoMessage::create('https://example.com/video.mp4', 'Caption!');
```

Handling Webhooks
-----------------

[](#handling-webhooks)

Zapply can notify your application of a variety of events via webhooks. By default, a route that points to Zapply's webhook controller is automatically registered by the Zapply service provider. This controller will handle all incoming webhook requests.

### Webhooks and CSRF Protection

[](#webhooks-and-csrf-protection)

Since Zapply webhooks need to bypass Laravel's CSRF protection, be sure to list the URI as an exception in your application's App\\Http\\Middleware\\VerifyCsrfToken middleware or list the route outside of the web middleware group:

```
protected $except = [
    'zapply/*',
];
```

### Defining Webhook Event Handlers

[](#defining-webhook-event-handlers)

You may handle webhhok events by listening to the following events that are dispatched:

- Zapply\\Laravel\\Events\\WebhookReceived
- Zapply\\Laravel\\Events\\WebhookHandled

Both events contain the full payload of Zapply webhook. For example, if you wish to handle the message webhook, you may register a listener that will handle the event:

```
