A simple API with Guzzle wrapper, providing easy access to wppconnect's endpoints.

Overview

WPPConnect Team

Wppconnect Laravel Client

A simple API with Guzzle wrapper, providing easy access to wppconnect's endpoints.

Requirements

  • PHP 7.4 or newer
  • Laravel 8.x or newer

Note that the above requirements will always reflect the latest release. Older releases may support older PHP and Laravel versions.

Install - Laravel

Require this package with Composer (Packagist), using the following command:

$ composer require wppconnect-team/wppconnect-laravel-client

Register the WppconnectServiceProvider to the providers array in config/app.php:

 WPPConnectTeam\Wppconnect\WppconnectServiceProvider::class

Publish vendor files (config file):

$ php artisan vendor:publish

Optional Register the facade in config/app.php:

'Wppconnect' => WPPConnectTeam\Wppconnect\Facades\Wppconnect::class

Config

Associative array of Request Options, that are applied to every request, created by the client.

Example:

'defaults' => [
     /**
      * Configures a base URL for the client so that requests created using a relative URL are combined with the base_url
      * See: http://guzzle.readthedocs.org/en/latest/quickstart.html#creating-a-client
      */
     'base_uri' => 'http://192.168.0.39:21465',

     /**
      * Secret Key
      * See: https://github.com/wppconnect-team/wppconnect-server#secret-key
      */
     'secret_key' => 'MYKeYPHP'
 ]

Usage

You can use this package without any configuration. Just use the Wppconnect facade in your controller or Inject into the class where you need the client:

/**
 * @var RequestInterface
 */
protected $client;

/**
 * @param Wppconnect $client
 */
public function __construct(Wppconnect $client)
{
    $this->client = $client;
}

Facade Example:

class WppconnectController extends Controller
{

    protected $url;
    protected $key;
    protected $session;

    /**
     * __construct function
     */
    public function __construct()
    {
        $this->url = config('wppconnect.defaults.base_uri');
        $this->key = config('wppconnect.defaults.secret_key');
	$this->session = "mySession";
    }

    public function index(){

	#Function: Generated Token
	# /api/:session/generate-token
	
        //Session::flush();
        if(!Session::get('token') and !Session::get('session')):
            Wppconnect::make($this->url);
            $response = Wppconnect::to('/api/'.$this->session.'/'.$this->key.'/generate-token')->asJson()->post();
            $response = json_decode($response->getBody()->getContents(),true);
            if($response['status'] == 'Success'):
                Session::put('token', $response['token']);
                Session::put('session', $response['session']);
            endif;
        endif;

	#Function: Start Session 
	# /api/:session/start-session
		
        if(Session::get('token') and Session::get('session') and !Session::get('init')):
            Wppconnect::make($this->url);
            $response = Wppconnect::to('/api/'.Session::get('session').'/start-session')->withHeaders([
                'Authorization' => 'Bearer '.Session::get('token')
            ])->asJson()->post();
            $response = json_decode($response->getBody()->getContents(),true);
            Session::put('init', true);
        endif;
	
    }
 }
   #Function: Check Connection Session
   # /api/:session/check-connection-session
   	
   if(Session::get('token') and Session::get('session') and Session::get('init')):
       Wppconnect::make($this->url);
       $response = Wppconnect::to('/api/'. Session::get('session').'/check-connection-session')->withHeaders([
   	'Authorization' => 'Bearer '.Session::get('token')
       ])->asJson()->get();
       $response = json_decode($response->getBody()->getContents(),true);
       dd($response);
   endif;
   #Function: Close Session
   # /api/:session/close-session

   if(Session::get('token') and Session::get('session') and Session::get('init')):
       Wppconnect::make($this->url);
       $response = Wppconnect::to('/api/'. Session::get('session').'/close-session')->withHeaders([
   	'Authorization' => 'Bearer '.Session::get('token')
       ])->asJson()->post();
       $response = json_decode($response->getBody()->getContents(),true);
       dd($response);
   endif;
   #Function: Send Message
   # /api/:session/send-message
   	
   if(Session::get('token') and Session::get('session') and Session::get('init')):
       Wppconnect::make($this->url);
       $response = Wppconnect::to('/api/'. Session::get('session').'/send-message')->withBody([
   	'phone' => '0000000000000',
   	'message' => 'Opa, funciona mesmo!'
       ])->withHeaders([
   	'Authorization' => 'Bearer '.Session::get('token')
       ])->asJson()->post();
       $response = json_decode($response->getBody()->getContents(),true);
       dd($response);
   endif;
   #Function: Send File Base64
   # /api/:session/send-file-base64
   	
   if(Session::get('token') and Session::get('session') and Session::get('init')):
       Wppconnect::make($this->url);
       $response = Wppconnect::to('/api/'. Session::get('session').'/send-file-base64')->withBody([
   	'phone' => '0000000000000',
   	'base64' => 'data:image/jpg;base64,' . base64_encode(file_get_contents(resource_path('/img/xpto.jpg')))
       ])->withHeaders([
   	'Authorization' => 'Bearer '.Session::get('token')
       ])->asJson()->post();
       $response = json_decode($response->getBody()->getContents(),true);
       dd($response);
   endif;

Debugging

Using debug(bool|resource) before sending a request turns on Guzzle's debugger, more information about that here.

The debugger is turned off after every request, if you need to debug multiple requests sent sequentially you will need to turn on debugging for all of them.

Example

$logFile = './client_debug_test.log';
$logFileResource = fopen($logFile, 'w+');

$this->client->debug($logFileResource)->to('post')->withBody([
	'foo' => 'bar'
])->asJson()->post();

fclose($logFileResource);

This writes Guzzle's debug information to client_debug_test.log.

License

The MIT License (MIT). Please see License File for more information.

Issues
Releases(1.0.1)
A simple API with Guzzle wrapper, providing easy access to wppconnect's endpoints.

WPPConnect Team Wppconnect Laravel Client A simple API with Guzzle wrapper, providing easy access to wppconnect's endpoints. Requirements PHP 7.4 or n

null 11 Jun 3, 2021
Omnipay for Laravel

Omnipay for Laravel 5/6/7/8 & Lumen Integrates the Omnipay PHP library with Laravel 5 via a ServiceProvider to make Configuring multiple payment tunne

Ignited Labs 442 Jun 2, 2021
Easy to use utility functions for everyday PHP projects. This is a port of the Lodash JS library to PHP

Lodash-PHP Lodash-PHP is a port of the Lodash JS library to PHP. It is a set of easy to use utility functions for everyday PHP projects. Lodash-PHP tr

Lodash PHP 433 Jun 10, 2021
A Twitter bot powered by Github Actions tweeing Wikidata milestones

Twitter WikidataMeter Bot I'm the code, and deployment of Twitter bot WikidataMeter. I tweet a few fun things about Wikidata as it grows. Tweets Feel

null 3 Jun 11, 2021
Rubix Server is a library for bringing your trained Rubix ML models into production.

Rubix Server is a library for bringing your trained Rubix ML models into production. Inference servers are stand-alone services that run on your private or public network and wrap your trained estimator in an API that can be queried locally or over the network in real-time using standard protocols. In addition, the library provides async-compatible client implementations for making queries to the server from your PHP applications.

Rubix 36 May 23, 2021
RMT is a handy tool to help releasing new version of your software

RMT - Release Management Tool RMT is a handy tool to help releasing new versions of your software. You can define the type of version generator you wa

Liip 430 Jun 13, 2021
A framework agnostic, multi-gateway payment processing library for PHP 5.6+

Omnipay An easy to use, consistent payment processing library for PHP Omnipay is a payment processing library for PHP. It has been designed based on i

The League of Extraordinary Packages 5.3k Jun 20, 2021
A set of utilities for working with vk api!

vk-utils Документация на русском языке Installation composer require labile/vk-utils How to use it? Simple example use Astaroth\VkUtils\Client; $api

null 3 Jun 14, 2021
CloudConvert PHP SDK

cloudconvert-php This is the official PHP SDK v3 for the CloudConvert API v2. For API v1, please use v2 branch of this repository. Install To install

null 184 Jun 15, 2021
Currency is a simple PHP library for current and historical currency exchange rates & crypto exchange rates. based on the free API exchangerate.host

Currency Currency is a simple PHP library for current and historical currency exchange rates & crypto exchange rates. based on the free API exchangera

Amr Shawky 5 Jun 9, 2021
A PHP library to play with the Raspberry PI's GPIO pins

php-gpio php-gpio is a simple PHP library to play with the Raspberry PI's GPIO pins. It provides simple tools such as reading & writing to pins. [UPDA

Ronan Guilloux 265 Apr 13, 2021
Formcreator is a plugin which allow creation of custom forms of easy access

Formcreator is a plugin which allow creation of custom forms of easy access. At the same time, the plugin allow the creation of one or more tickets when the form is filled.

GLPI plugins 100 Jun 12, 2021
Port of the Java Content Repository (JCR) to PHP.

PHP Content Repository PHPCR This repository contains interfaces for the PHPCR standard. The JSR-283 specification defines an API for a Content Reposi

PHPCR 423 May 24, 2021
FreshRSS is a self-hosted RSS feed aggregator like Leed or Kriss Feed.

Read this document on github.com/FreshRSS/FreshRSS/ to get the correct links and pictures. Version française FreshRSS FreshRSS is a self-hosted RSS fe

FreshRSS 3.3k Jun 21, 2021