Giter VIP home page Giter VIP logo

whatsapp-php-sdk's Introduction

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

Youtube

Send Message by WhatsApp api using PHP SDK | Ultramsg PHP SDK

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

  • $referenceId : Your custom reference ID for this message.
$to="put_your_mobile_number_here"; 
$body="Hello world";
$priority=10;
$referenceId="SDK";
$api=$client->sendChatMessage($to,$body,$priority,$referenceId);
print_r($api);

Send Image

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

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

Max file size : 16MB .

Max Base64 length : 10,000,000

  • $nocache : default false

false : use a previously uploaded file instead of uploading it with each request

true : uploading it each request

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

Send Sticker

  • $sticker : HTTP link image or base64-encoded file

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

Max file size : 16MB .

Max Base64 length : 10,000,000

  • $nocache : default false

false : use a previously uploaded file instead of uploading it with each request

true : uploading it each request

$to="put_your_mobile_number_here"; 
$sticker="https://file-example.s3.us-west-2.amazonaws.com/sticker/1.webp";  
$priority=10;
$referenceId="SDK";
$nocache=false; 
$api=$client->sendStickerMessage($to,$sticker,$priority,$referenceId,$nocache);
print_r($api);

Send Document

  • $filename : File name, for example 1.jpg or Hello.pdf
  • $caption : Document Caption, UTF-8 or UTF-16 string with emoji .
  • $document : HTTP link file or base64-encoded file

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

Max file size : 100MB .

Max Base64 length : 10,000,000

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

Send Audio

  • $audio : HTTP link audio or base64-encoded audio

Supported extensions ( mp3 , aac , ogg ) .

Max file size : 16MB .

Max Base64 length : 10,000,000

$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

Max file size : 16MB .

Max Base64 length : 10,000,000

$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

Supported extensions ( mp4 , 3gp , mov ) .

Max file size : 16MB .

Max Base64 length : 10,000,000

$to="put_your_mobile_number_here"; 
$video="https://file-example.s3-accelerate.amazonaws.com/video/test.mp4";
$caption="video Caption"; 
$api=$client->sendVideoMessage($to,$video,$caption);
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);

Resend messages by status

  • $status : unsent or expired
$status="expired";
$api=$client->resendByStatus($status);
print_r($api);

Resend message by ID

  • $id : message id
$id=123;
$api=$client->resendById($id);
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 .
    • invalid : get invalid messages .
    • expired : get expired messages .
    • all : get all messages .
  • $sort :
    • asc : sorted messages by ID from smallest to largest .
    • desc : sorted messages by ID from largest to smallest .
  • $id : filter messages by message ID .
  • $referenceId : filter messages by your custom reference ID .
  • $from : filter messages by WhatsApp sender number e.g [email protected] .
  • $to : filter messages by recipient number e.g [email protected] or [email protected] .
  • $ack : filter messages by message ack status [ pending , server , device , read , played ] .
$page=1;
$limit=100;
$status="all";
$sort="asc";
$id="";
$referenceId="";
$from="";
$to="";
$ack="";
$api=$client->getMessages($page,$limit,$status,$sort,$id,$referenceId,$from,$to,$ack);
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 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 .

webhook_message_download_media : on/off to get received document / media files.

$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;
$webhook_message_download_media=false;

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

Get the chats list

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

get last message from chat conversation

max value : 1000 .

$chatId="[email protected]";
$limit=100;
$api=$client->getChatsMessages($chatId,$limit);
print_r($api);

Get the contacts list

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

Get contact info

$chatId="[email protected]"; 
$api=$client->getContact($chatId);
print_r($api);

Gets all blocked contacts

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

block contact from WhatsApp

$chatId="[email protected]"; 
$api=$client->blockContact($chatId);
print_r($api);

Unblock contact from WhatsApp

$chatId="[email protected]"; 
$api=$client->unblockContact($chatId);
print_r($api);

Check if number is WhatsApp user

$chatId="[email protected]"; 
$api=$client->checkContact($chatId);
print_r($api);

Support

Use Issues to contact me

whatsapp-php-sdk's People

Contributors

ultramsg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

whatsapp-php-sdk's Issues

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

Send Location

i have try send location example, but have error.. can help?
how to contact ultramsg via whatsapp?

can i get whatsapp number?

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?

Delivery Status Failure

Hi,
Since 19/4/2022 19:28:47, I no longer receive Delivery and Read Status, both on Dashboard and on API calls.
Kindly rectify.
Thanks

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; }

The referenceId was not implemented.

The referenceId was not implemented. Was there a reason for that?
That is forcing me to fork the repo and implement that part.
Is that permitted?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.