Lightweight PHP library for WhatsApp API to send the whatsapp messages in PHP provided by ultramsg.com

Overview

Ultramsg.com WhatsApp API PHP SDK

Lightweight PHP library for WhatsApp API to send the whatsappp messages in PHP provided by Ultramsg.com

Installation

Just download ultramsg.class.php or use Composer:

composer require ultramsg/whatsapp-php-sdk

Example usage

<?php
require_once ('vendor/autoload.php'); // if you use Composer
//require_once('ultramsg.class.php'); // if you download ultramsg.class.php

$ultramsg_token="tof7lsdJasdloaa57e"; // Ultramsg.com token
$instance_id="instance1150"; // Ultramsg.com instance id
$client = new UltraMsg\WhatsAppApi($ultramsg_token,$instance_id);

$to="put_your_mobile_number_here"; 
$body="Hello world"; 
$api=$client->sendChatMessage($to,$body);
print_r($api);

NOTE: you need replace instance_id and token with yours in ultramsg.com account if you don't have account create one from here

Send Message

  • $to : your number for testing with international format e.g. +14155552671 or chatID for contact or group e.g [email protected] or [email protected]
  • $body : Message text, UTF-8 or UTF-16 string with emoji .
  • $priority : This parameter is optional,

You can use it to create a professional queue for messages, The Messages with less priority value are sent first.

example of usage :

priority = 0: for High priority like OTP messages.

priority = 5: used with general messages.

priority =10: Non-urgent promotional offers and notifications to your customers.

Default value : 10

$to="put_your_mobile_number_here"; 
$body="Hello world";
$priority=10;
$api=$client->sendChatMessage($to,$body,$priority);
print_r($api);

Send Image

  • $caption : image Caption, UTF-8 or UTF-16 string with emoji .
  • $image : HTTP link image or base64-encoded file with mime data

Supported extensions ( jpg , jpeg , gif , png , svg , webp , bmp ) .

Max file size : 64MB .

example images links :

$to="put_your_mobile_number_here"; 
$caption="image Caption"; 
$image="https://file-example.s3-accelerate.amazonaws.com/images/test.jpg"; 
$api=$client->sendImageMessage($to,$caption,$image);
print_r($api);

Send Document

  • $filename : File name, for example 1.jpg or Hello.pdf
  • $document : HTTP link file or base64-encoded file with mime data

Supported most extensions like ( zip , xlsx , csv , txt , pptx , docx ....etc ) .

Max file size : 64MB .

$to="put_your_mobile_number_here"; 
$filename="image Caption"; 
$document="https://file-example.s3-accelerate.amazonaws.com/documents/cv.pdf"; 
$api=$client->sendDocumentMessage($to,$filename,$document);
print_r($api);

Send Audio

  • $audio : HTTP link audio or base64-encoded audio with mime data

Supported extensions ( mp3 , aac , ogg ) .

Max file size : 64MB .

$to="put_your_mobile_number_here"; 
$audio="https://file-example.s3-accelerate.amazonaws.com/audio/2.mp3"; 
$api=$client->sendAudioMessage($to,$audio);
print_r($api);

Send Voice

  • $audio : HTTP link audio ogg-file with opus codec or base64 ogg-file in opus codec
$to="put_your_mobile_number_here"; 
$audio="https://file-example.s3-accelerate.amazonaws.com/voice/oog_example.ogg"; 
$api=$client->sendVoiceMessage($to,$audio);
print_r($api);

Send Video

  • $video : HTTP link video or base64-encoded video with mime data

Supported extensions ( mp4 , 3gp , mov ) .

Max file size : 64MB .

$to="put_your_mobile_number_here"; 
$video="https://file-example.s3-accelerate.amazonaws.com/video/test.mp4"; 
$api=$client->sendVideoMessage($to,$video);
print_r($api);

Send Link

  • $link : HTTP or HTTPS link
$to="put_your_mobile_number_here"; 
$link="https://ultramsg.com"; 
$api=$client->sendLinkMessage($to,$link);
print_r($api);

Send Contact

  • $contact :Contact ID or Contact IDs array example :

Example

[email protected]

or

[email protected],[email protected],[email protected]

Max length : 300 char, almost 15 contacts

$to="put_your_mobile_number_here"; 
$contact="[email protected]"; 
$api=$client->sendContactMessage($to,$contact);
print_r($api);

Send Location

  • $address : Text under the location.

Supports two lines. To use two lines, use the \n symbol.

Max length : 300 char .

  • $lat : Latitude
  • $lng : longitude
$to="put_your_mobile_number_here"; 
$address="ABC company \n Sixth floor , office 38"; 
$lat="25.197197"; 
$lng="55.2721877"; 
$api=$client->sendLocationMessage($to,$address,$lat,$lng);
print_r($api);

Send Vcard

  • $vcard : Text value vcard 3.0

Max length : 4096 char

$to="put_your_mobile_number_here"; 
$vcard="BEGIN:VCARD
VERSION:3.0
N:lastname;firstname
FN:firstname lastname
TEL;TYPE=CELL;waid=14000000001:14000000002
NICKNAME:nickname
BDAY:01.01.1987
X-GENDER:M
NOTE:note
ADR;TYPE=home
ADR;TYPE=work
END:VCARD";
$vcard = preg_replace("/[\n\r]/", "\n", $vcard);
$api=$client->sendVcardMessage($to,$vcard);
print_r($api);

Get Messages

get the messages that sent by api

  • $page : pagination page number
  • $limit : number of messages per request . max value : 100 .
  • $status : Messages status [sent , queue , unsent]
    • sent : get sent messages .
    • queue : get queue messages .
    • unsent : get unsent messages .
    • all : get all messages .
  • $sort :
    • asc : sorted messages by ID from smallest to largest .
    • desc : sorted messages by ID from largest to smallest .
$page=1;
$limit=100;
$status="all";
$sort="asc";
$api=$client->getMessages($page,$limit,$status,$sort);
print_r($api);

Get Messages Statistics

$api=$client->getMessageStatistics();
print_r($api);

Get Instance Status

$api=$client->getInstanceStatus();
print_r($api);

Get Instance QR Image

header('Content-Type: image/png');
$api=$client->getInstanceQr();
print_r($api);

Get Instance QR Code

$api=$client->getInstanceQrCode();
print_r($api);

Get Instance Screenshot

header('Content-Type: image/png');
$api=$client->getInstanceScreenshot();
print_r($api);

or base64

$api=$client->getInstanceScreenshot("base64");
print_r($api);

Get Instance Info

Get connected phone informations : number , name , image etc..

$api=$client->getInstanceMe();
print_r($api);

Get Instance Settings

sendDelay : Delay in seconds between sending message, Default 1 second

webhook_url : Http or https URL for receiving notifications .

webhook_message_ack : on/off ack (message delivered and message viewed) notifications in webhooks.

webhook_message_received : on/off notifications in webhooks when message received .

webhook_message_create : on/off notifications in webhooks when message create .

$api=$client->getInstanceSettings();
print_r($api);

Instance Takeover

Returns the active session if the device has connected to another instance of Web WhatsApp

$api=$client->sendInstanceTakeover();
print_r($api);

Instance Logout

Logout from WhatsApp Web to get new QR code.

$api=$client->sendInstanceLogout();
print_r($api);

Instance Restart

Restart your instance.

$api=$client->sendInstanceRestart();
print_r($api);

Instance Settings Update

  • sendDelay : Delay in seconds between sending message .

  • webhook_url : Http or https URL for receiving notifications .

  • webhook_message_received : true/false notifications in webhooks when message received .

  • webhook_message_create : true/false notifications in webhooks when message create .

  • webhook_message_ack : true/false ack (message delivered and message viewed) notifications in webhooks.

$sendDelay=1;
$webhook_url="";
$webhook_message_received=false;
$webhook_message_create=false;
$webhook_message_ack=false;

$api=$client->sendInstanceSettings($sendDelay,$webhook_url,$webhook_message_received,$webhook_message_create,$webhook_message_ack);
print_r($api);

Support

Use Issues to contact me

You might also like...
A PHP library for the Campaign Monitor API

createsend A PHP library which implements the complete functionality of the Campaign Monitor API. Installation Composer If you use Composer, you can r

PHP 5.3+ library which helps you to interact with the DigitalOcean API

DigitalOcean The version 2 of the API will be available soon ! Please visit DigitalOceanV2 and contribute :) This PHP 5.3+ library helps you to intera

PHP library for the GitHub API v3

GitHub API v3 - PHP Library Currently under construction. Overview Provides access to GitHub API v3 via an Object Oriented PHP library. The goal of th

PHP library to use IOTA REST API to help node management and tangle queries

iota.php About PHP library to use IOTA REST API to help node management and tangle queries. Please be aware that this library is in an early developme

PHP library for the ArvanCloud API

PHP ArvanCloud API PHP library for the ArvanCloud API. This package supports PHP 7.3+. For Laravel integration you can use mohammadv184/arvancloud-lar

A library written in PHP to interact with Coinbase Pro via API.

A library written in PHP to interact with Coinbase Pro via API.

Upload Vimeo video with CodeIgniter, Official PHP library for the Vimeo API

Upload Vimeo video with CodeIgniter, Official PHP library for the Vimeo API. Vimeo Video upload with API using Official PHP library for the Vimeo API.

The library provides convenient access to the Epoint.az API from applications written in the PHP language.

Tural/Epoint library/SDK The library provides convenient access to the Epoint.az API from applications written in the PHP language. It includes a pre-

The library provides convenient access to the Epoint.az API from applications written in the PHP language.

Tural/Epoint library/SDK The library provides convenient access to the Epoint.az API from applications written in the PHP language. It includes a pre-

Comments
  • Send Message in Proper Formatted Manner

    Send Message in Proper Formatted Manner

    This library is remarkably amazing, this solved my headache with low cost, but need guidance on How to send a msg in a proper formatted manner like with new line and indentation and how can I send link with my proper formatted message. #highpriority

    opened by khanmudassir124 1
  • Fix for PHP 8.0

    Fix for PHP 8.0

    -Deprecated: Required parameter $image follows optional parameter $caption on line 41 -Deprecated: Required parameter $video follows optional parameter $caption on line 61 -Updated Readme

    opened by Bauhu 1
  • ReferenceID Absence in Webhook Response Payload

    ReferenceID Absence in Webhook Response Payload

    I have implemented the update on the reference ID bit. But I observed that the Response/Request hitting my webhook after sending messages, does not come back with the custom ReferenceId. There could be a reason I decided to customize the referenceId instead of using just the message[id]...Encoding of special User Data for instance. So, it's paramount that it comes back in the webhook Callback. Could this be looked into please?

    opened by hexxondiv 1
  • I tried send a message

    I tried send a message

    show this error cURL Error #:SSL certificate problem: certificate has expired

    the code is similar to page

    "https://api.ultramsg.com/instance3857/messages/chat", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => "token=f8yyphpu5xjj4nw8&to=+584241300079&body=La API de WhatsApp en UltraMsg.com funciona bien&priority=1&referenceId=", CURLOPT_HTTPHEADER => array( "content-type: application/x-www-form-urlencoded" ), )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; }
    opened by carlosdfb 1
Releases(2.0.7)
Owner
Ultramsg
WhatsApp API gateway for chatbot and sending messages, media, marketing campaigns for PHP, nodejs , JavaScript, and Python
Ultramsg
A tool for sending fast and managed messages to Telegram bot users

???? HiToAll A tool for sending fast and managed messages to Telegram bot users About In some telegram bots programmed with php language, if there are

Matin Najafi 3 Oct 3, 2021
A Discord bot that rewards players in Minecraft for sending messages on Discord

MCRewards-Discord-Bot A Discord bot that rewards players in Minecraft for sending messages on Discord How to setup: Download this git as a .zip, or cl

null 3 Dec 26, 2021
Laravel Package for 1APP. Learn how to integrate our APIs to build a web or mobile integration to send and accept payments for your application and businesses.

1APP Laravel Library Learn how to integrate our APIs to build a web or mobile integration to accept payments, make payment of Bills and as well custom

O'Bounce Technologies 4 Jul 25, 2022
OVHcloud APIs lightweight PHP wrapper

Lightweight PHP wrapper for OVHcloud APIs - The easiest way to use OVHcloud APIs in your PHP applications - Compatible with PHP 7.4, 8.0, 8.1 - Not affiliated with OVHcloud

Germain Carré 3 Sep 10, 2022
OpenAI API Client is a component-oriented, extensible client library for the OpenAI API. It's designed to be faster and more memory efficient than traditional PHP libraries.

OpenAI API Client in PHP (community-maintained) This library is a component-oriented, extensible client library for the OpenAI API. It's designed to b

Mounir R'Quiba 6 Jun 14, 2023
BeckhoffPLCSoapClient - SoapClient to communicate with BeckHoff PLC. Library made in PHP based on TcAdsWebService JavaScript Library.

BeckhoffPLCSoapClient - SoapClient to communicate with BeckHoff PLC. Library made in PHP based on TcAdsWebService JavaScript Library.

null 3 May 18, 2022
Google-api-php-client - A PHP client library for accessing Google APIs

Google APIs Client Library for PHP Reference Docs https://googleapis.github.io/google-api-php-client/main/ License Apache 2.0 The Google API Client Li

Google APIs 8.4k Dec 30, 2022
Wise-php - This library is written to accommodate the wise API's use in php projects With Wise

Wise-php - This library is written to accommodate the wise API's use in php projects With Wise you can automate payments, connect your business tools, and create ways to manage your finances. You can also power your cross-border and domestic payouts.

Albert Xhani 15 Nov 17, 2022
PHP library for the Stripe API.

Stripe PHP bindings The Stripe PHP library provides convenient access to the Stripe API from applications written in the PHP language. It includes a p

Stripe 3.3k Jan 5, 2023
A PHP library for communicating with the Twilio REST API and generating TwiML.

twilio-php The default branch name for this repository has been changed to main as of 07/27/2020. Documentation The documentation for the Twilio API c

Twilio 1.4k Jan 2, 2023