{"id":13404796,"url":"https://github.com/ultramsg/whatsapp-php-sdk","last_synced_at":"2025-04-04T18:09:56.999Z","repository":{"id":57074984,"uuid":"432805977","full_name":"ultramsg/whatsapp-php-sdk","owner":"ultramsg","description":"Lightweight PHP library for WhatsApp API to send the whatsapp messages in PHP provided by ultramsg.com","archived":false,"fork":false,"pushed_at":"2023-08-12T15:07:06.000Z","size":51,"stargazers_count":162,"open_issues_count":0,"forks_count":95,"subscribers_count":8,"default_branch":"main","last_synced_at":"2024-04-14T05:40:01.404Z","etag":null,"topics":["php","sdk","whatsapp","whatsapp-api","whatsapp-api-php","whatsapp-bot","whatsapp-chat","whatsapp-web"],"latest_commit_sha":null,"homepage":"https://ultramsg.com","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ultramsg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-11-28T19:31:12.000Z","updated_at":"2024-06-19T04:07:56.821Z","dependencies_parsed_at":"2024-06-19T04:07:56.119Z","dependency_job_id":"1f27002f-23d5-4b98-aff1-6fc6a3296b9f","html_url":"https://github.com/ultramsg/whatsapp-php-sdk","commit_stats":{"total_commits":28,"total_committers":1,"mean_commits":28.0,"dds":0.0,"last_synced_commit":"a2a44b788524993f718011f6f018ff82a36a6ab9"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ultramsg%2Fwhatsapp-php-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ultramsg%2Fwhatsapp-php-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ultramsg%2Fwhatsapp-php-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ultramsg%2Fwhatsapp-php-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ultramsg","download_url":"https://codeload.github.com/ultramsg/whatsapp-php-sdk/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247226215,"owners_count":20904465,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["php","sdk","whatsapp","whatsapp-api","whatsapp-api-php","whatsapp-bot","whatsapp-chat","whatsapp-web"],"created_at":"2024-07-30T19:01:51.540Z","updated_at":"2025-04-04T18:09:56.977Z","avatar_url":"https://github.com/ultramsg.png","language":"PHP","funding_links":[],"categories":["PHP"],"sub_categories":[],"readme":"# [Ultramsg.com](https://ultramsg.com/?utm_source=github\u0026utm_medium=php\u0026utm_campaign=api) WhatsApp API PHP SDK\r\n\r\n Lightweight PHP library for WhatsApp API to send the whatsappp messages in PHP provided by [Ultramsg.com](https://ultramsg.com/?utm_source=github\u0026utm_medium=php\u0026utm_campaign=api)\r\n\r\n# Installation\r\n\r\nJust download ultramsg.class.php or use Composer: \r\n\r\n```\r\ncomposer require ultramsg/whatsapp-php-sdk\r\n```\r\n\r\n\r\n# Example usage\r\n\r\n```php\r\n\u003c?php\r\nrequire_once ('vendor/autoload.php'); // if you use Composer\r\n//require_once('ultramsg.class.php'); // if you download ultramsg.class.php\r\n\r\n$ultramsg_token=\"tof7lsdJasdloaa57e\"; // Ultramsg.com token\r\n$instance_id=\"instance1150\"; // Ultramsg.com instance id\r\n$client = new UltraMsg\\WhatsAppApi($ultramsg_token,$instance_id);\r\n\r\n$to=\"put_your_mobile_number_here\"; \r\n$body=\"Hello world\"; \r\n$api=$client-\u003esendChatMessage($to,$body);\r\nprint_r($api);\r\n```\r\n \u003e **NOTE:**  you need replace instance_id and token with yours in [ultramsg.com](https://ultramsg.com/?utm_source=github\u0026utm_medium=php\u0026utm_campaign=api) account if you don't have account create one from [here](https://ultramsg.com/?utm_source=github\u0026utm_medium=php\u0026utm_campaign=api)\r\n\r\n# Youtube\r\n[![Send Message by WhatsApp api using PHP SDK | Ultramsg PHP SDK\r\n](https://img.youtube.com/vi/OqDOKyMIp20/0.jpg)](https://www.youtube.com/watch?v=OqDOKyMIp20)\r\n\r\n\r\n## Send Message\r\n* **$to** :  your number for testing with international format e.g. +14155552671 or chatID for contact or group e.g 14155552671@c.us or 14155552671-441234567890@g.us\r\n* **$body** : Message text, UTF-8 or UTF-16 string with emoji .\r\n* **$priority** : This parameter is optional,\r\n\r\nYou can use it to create a professional queue for messages, The Messages with less priority value are sent first.\r\n\r\nexample of usage :\r\n\r\npriority = 0: for High priority like OTP messages.\r\n\r\npriority = 5: used with general messages.\r\n\r\npriority =10: Non-urgent promotional offers and notifications to your customers.\r\n\r\n**Default value** : 10\r\n* **$referenceId** : Your custom reference ID for this message.\r\n```php\r\n$to=\"put_your_mobile_number_here\"; \r\n$body=\"Hello world\";\r\n$priority=10;\r\n$referenceId=\"SDK\";\r\n$api=$client-\u003esendChatMessage($to,$body,$priority,$referenceId);\r\nprint_r($api);\r\n```\r\n\r\n## Send Image \r\n* **$caption** : image Caption, UTF-8 or UTF-16 string with emoji .\r\n* **$image** : HTTP link image or base64-encoded file\r\n\r\nSupported extensions ( jpg , jpeg , gif , png , svg , webp , bmp ) .\r\n\r\nMax file size : 16MB .\r\n\r\nMax Base64 length : 10,000,000\r\n\r\n* **$nocache** : default false\r\n\r\nfalse : use a previously uploaded file instead of uploading it with each request\r\n\r\ntrue : uploading it each request\r\n\r\n```php\r\n$to=\"put_your_mobile_number_here\"; \r\n$image=\"https://file-example.s3-accelerate.amazonaws.com/images/test.jpg\"; \r\n$caption=\"image Caption\"; \r\n$priority=10;\r\n$referenceId=\"SDK\";\r\n$nocache=false; \r\n$api=$client-\u003esendImageMessage($to,$image,$caption,$priority,$referenceId,$nocache);\r\nprint_r($api);\r\n\r\n```\r\n## Send Sticker  \r\n* **$sticker** : HTTP link image or base64-encoded file\r\n\r\nSupported extensions ( jpg , jpeg , gif , png , svg , webp , bmp ) .\r\n\r\nMax file size : 16MB .\r\n\r\nMax Base64 length : 10,000,000\r\n\r\n* **$nocache** : default false\r\n\r\nfalse : use a previously uploaded file instead of uploading it with each request\r\n\r\ntrue : uploading it each request\r\n\r\n```php\r\n$to=\"put_your_mobile_number_here\"; \r\n$sticker=\"https://file-example.s3.us-west-2.amazonaws.com/sticker/1.webp\";  \r\n$priority=10;\r\n$referenceId=\"SDK\";\r\n$nocache=false; \r\n$api=$client-\u003esendStickerMessage($to,$sticker,$priority,$referenceId,$nocache);\r\nprint_r($api);\r\n```\r\n\r\n## Send Document \r\n* **$filename** : File name, for example 1.jpg or Hello.pdf\r\n* **$caption** : Document Caption, UTF-8 or UTF-16 string with emoji .\r\n* **$document** : HTTP link file or base64-encoded file\r\n\r\nSupported most extensions like ( zip , xlsx , csv , txt , pptx , docx ....etc ) .\r\n\r\nMax file size : 100MB .\r\n\r\nMax Base64 length : 10,000,000\r\n\r\n```php\r\n$to=\"put_your_mobile_number_here\"; \r\n$filename=\"File name\"; \r\n$caption=\"Document Caption\"; \r\n$document=\"https://file-example.s3-accelerate.amazonaws.com/documents/cv.pdf\"; \r\n$api=$client-\u003esendDocumentMessage($to,$filename,$document,$caption);\r\nprint_r($api);\r\n```\r\n\r\n## Send Audio \r\n* **$audio** : HTTP link audio or base64-encoded audio \r\n\r\nSupported extensions ( mp3 , aac , ogg ) .\r\n\r\nMax file size : 16MB .\r\n\r\nMax Base64 length : 10,000,000\r\n\r\n```php \r\n$to=\"put_your_mobile_number_here\"; \r\n$audio=\"https://file-example.s3-accelerate.amazonaws.com/audio/2.mp3\"; \r\n$api=$client-\u003esendAudioMessage($to,$audio);\r\nprint_r($api);\r\n```\r\n## Send Voice \r\n* **$audio** : HTTP link audio ogg-file with opus codec or base64 ogg-file in opus codec\r\n\r\nMax file size : 16MB .\r\n\r\nMax Base64 length : 10,000,000\r\n\r\n```php \r\n$to=\"put_your_mobile_number_here\"; \r\n$audio=\"https://file-example.s3-accelerate.amazonaws.com/voice/oog_example.ogg\"; \r\n$api=$client-\u003esendVoiceMessage($to,$audio);\r\nprint_r($api);\r\n```\r\n\r\n## Send Video \r\n* **$video** : HTTP link video or base64-encoded video  \r\n\r\nSupported extensions ( mp4 , 3gp , mov ) .\r\n\r\nMax file size : 16MB .\r\n\r\nMax Base64 length : 10,000,000\r\n\r\n```php \r\n$to=\"put_your_mobile_number_here\"; \r\n$video=\"https://file-example.s3-accelerate.amazonaws.com/video/test.mp4\";\r\n$caption=\"video Caption\"; \r\n$api=$client-\u003esendVideoMessage($to,$video,$caption);\r\nprint_r($api);\r\n```\r\n## Send Link \r\n* **$link** : HTTP or HTTPS link\r\n\r\n```php \r\n$to=\"put_your_mobile_number_here\"; \r\n$link=\"https://ultramsg.com\"; \r\n$api=$client-\u003esendLinkMessage($to,$link);\r\nprint_r($api);\r\n```\r\n## Send Contact \r\n* **$contact** :Contact ID or Contact IDs array example :\r\n\r\nExample\r\n\r\n14000000001@c.us\r\n\r\nor\r\n\r\n14000000001@c.us,14000000002@c.us,14000000003@c.us\r\n\r\nMax length : 300 char, almost 15 contacts\r\n```php \r\n$to=\"put_your_mobile_number_here\"; \r\n$contact=\"14000000001@c.us\"; \r\n$api=$client-\u003esendContactMessage($to,$contact);\r\nprint_r($api);\r\n```\r\n## Send Location \r\n* **$address** : Text under the location.\r\n\r\nSupports two lines. To use two lines, use the \\n symbol.\r\n\r\nMax length : 300 char .\r\n* **$lat** : Latitude\r\n* **$lng** : longitude\r\n```php \r\n$to=\"put_your_mobile_number_here\"; \r\n$address=\"ABC company \\n Sixth floor , office 38\"; \r\n$lat=\"25.197197\"; \r\n$lng=\"55.2721877\"; \r\n$api=$client-\u003esendLocationMessage($to,$address,$lat,$lng);\r\nprint_r($api);\r\n```\r\n## Send Vcard \r\n* **$vcard** : Text value vcard 3.0\r\n\r\nMax length : 4096 char\r\n\r\n```php \r\n$to=\"put_your_mobile_number_here\"; \r\n$vcard=\"BEGIN:VCARD\r\nVERSION:3.0\r\nN:lastname;firstname\r\nFN:firstname lastname\r\nTEL;TYPE=CELL;waid=14000000001:14000000002\r\nNICKNAME:nickname\r\nBDAY:01.01.1987\r\nX-GENDER:M\r\nNOTE:note\r\nADR;TYPE=home\r\nADR;TYPE=work\r\nEND:VCARD\";\r\n$vcard = preg_replace(\"/[\\n\\r]/\", \"\\n\", $vcard);\r\n$api=$client-\u003esendVcardMessage($to,$vcard);\r\nprint_r($api);\r\n```\r\n\r\n## Resend messages by status \r\n* **$status** :  unsent or expired\r\n \r\n```php \r\n$status=\"expired\";\r\n$api=$client-\u003eresendByStatus($status);\r\nprint_r($api);\r\n```\r\n\r\n## Resend message by ID \r\n* **$id** :   message id\r\n \r\n```php\r\n$id=123;\r\n$api=$client-\u003eresendById($id);\r\nprint_r($api);\r\n```\r\n\r\n## Get Messages\r\nget the messages that sent by api\r\n\r\n* **$page** : pagination page number\r\n* **$limit** : number of messages per request . max value : 100 .\r\n* **$status** : Messages status [sent , queue , unsent]\r\n  - sent : get sent messages .\r\n  - queue : get queue messages .\r\n  - unsent : get unsent messages .\r\n  - invalid : get invalid messages .\r\n  - expired : get expired messages .\r\n  - all : get all messages .\r\n* **$sort** :  \r\n  - asc : sorted messages by ID from smallest to largest .\r\n  - desc : sorted messages by ID from largest to smallest .\r\n* **$id** : filter messages by message ID .\r\n* **$referenceId** : filter messages by your custom reference ID .\r\n* **$from** : filter messages by WhatsApp sender number e.g 14155552671@c.us .\r\n* **$to** : filter messages by recipient number  e.g 14155552671@c.us or 14155552671-441234567890@g.us .\r\n* **$ack** : filter messages by message ack status [ pending , server , device , read , played ] .\r\n\r\n\r\n```php \r\n$page=1;\r\n$limit=100;\r\n$status=\"all\";\r\n$sort=\"asc\";\r\n$id=\"\";\r\n$referenceId=\"\";\r\n$from=\"\";\r\n$to=\"\";\r\n$ack=\"\";\r\n$api=$client-\u003egetMessages($page,$limit,$status,$sort,$id,$referenceId,$from,$to,$ack);\r\nprint_r($api);\r\n```\r\n\r\n## Get Messages Statistics \r\n\r\n```php \r\n$api=$client-\u003egetMessageStatistics();\r\nprint_r($api);\r\n```\r\n\r\n## Get Instance Status \r\n\r\n```php \r\n$api=$client-\u003egetInstanceStatus();\r\nprint_r($api);\r\n```\r\n\r\n## Get Instance QR Image\r\n\r\n```php \r\nheader('Content-Type: image/png');\r\n$api=$client-\u003egetInstanceQr();\r\nprint_r($api);\r\n```\r\n## Get Instance QR Code \r\n\r\n```php  \r\n$api=$client-\u003egetInstanceQrCode();\r\nprint_r($api);\r\n```\r\n\r\n## Get Instance Info\r\nGet connected phone informations : number , name , image etc..\r\n```php\r\n$api=$client-\u003egetInstanceMe();\r\nprint_r($api);\r\n```\r\n## Get Instance Settings\r\nsendDelay : Delay in seconds between sending message, Default 1 second\r\n\r\nwebhook_url : Http or https URL for receiving notifications .\r\n\r\nwebhook_message_ack : on/off ack (message delivered and message viewed) notifications in webhooks.\r\n\r\nwebhook_message_received : on/off notifications in webhooks when message received .\r\n\r\nwebhook_message_create : on/off notifications in webhooks when message create .\r\n\r\nwebhook_message_download_media  :  on/off to get received document / media files.\r\n```php\r\n$api=$client-\u003egetInstanceSettings();\r\nprint_r($api);\r\n```\r\n\r\n## Instance Takeover\r\nReturns the active session if the device has connected to another instance of Web WhatsApp\r\n\r\n```php  \r\n$api=$client-\u003esendInstanceTakeover();\r\nprint_r($api);\r\n```\r\n## Instance Logout\r\nLogout from WhatsApp Web to get new QR code.\r\n\r\n```php  \r\n$api=$client-\u003esendInstanceLogout();\r\nprint_r($api);\r\n```\r\n## Instance Restart\r\nRestart your instance.\r\n\r\n```php  \r\n$api=$client-\u003esendInstanceRestart();\r\nprint_r($api);\r\n```\r\n## Instance Settings Update\r\n* **sendDelay** : Delay in seconds between sending message .\r\n\r\n* **webhook_url** : Http or https URL for receiving notifications .\r\n\r\n* **webhook_message_received** : true/false notifications in webhooks when message received .\r\n\r\n* **webhook_message_create** : true/false notifications in webhooks when message create .\r\n\r\n* **webhook_message_ack** : true/false ack (message delivered and message viewed) notifications in webhooks.\r\n\r\n```php  \r\n$sendDelay=1;\r\n$webhook_url=\"\";\r\n$webhook_message_received=false;\r\n$webhook_message_create=false;\r\n$webhook_message_ack=false;\r\n$webhook_message_download_media=false;\r\n\r\n$api=$client-\u003esendInstanceSettings($sendDelay,$webhook_url,$webhook_message_received,$webhook_message_create,$webhook_message_ack,$webhook_message_download_media);\r\nprint_r($api);\r\n```\r\n\r\n## Get the chats list\r\n\r\n```php  \r\n$api=$client-\u003egetChats();\r\nprint_r($api);\r\n```\r\n\r\n## get last message from chat conversation\r\n\r\n* **$chatId** : chatID for contact or group e.g 14155552671@c.us or 14155552671-441234567890@g.us\r\n* **$limit** : number of messages per request .\r\n\r\nmax value : 1000 .\r\n\r\n```php  \r\n$chatId=\"14155552671@c.us\";\r\n$limit=100;\r\n$api=$client-\u003egetChatsMessages($chatId,$limit);\r\nprint_r($api);\r\n```\r\n\r\n\r\n## Get the contacts list\r\n\r\n```php  \r\n$api=$client-\u003egetContacts();\r\nprint_r($api);\r\n```\r\n\r\n## Get contact info\r\n\r\n* **$chatId** : chatID for contact e.g 14155552671@c.us \r\n\r\n```php  \r\n$chatId=\"14155552671@c.us\"; \r\n$api=$client-\u003egetContact($chatId);\r\nprint_r($api);\r\n```\r\n\r\n\r\n## Gets all blocked contacts\r\n\r\n```php  \r\n$api=$client-\u003egetBlockedContacts();\r\nprint_r($api);\r\n```\r\n\r\n## block contact from WhatsApp\r\n\r\n* **$chatId** : chatID for contact e.g 14155552671@c.us \r\n\r\n```php  \r\n$chatId=\"14155552671@c.us\"; \r\n$api=$client-\u003eblockContact($chatId);\r\nprint_r($api);\r\n```\r\n\r\n## Unblock contact from WhatsApp\r\n\r\n* **$chatId** : chatID for contact e.g 14155552671@c.us \r\n\r\n```php  \r\n$chatId=\"14155552671@c.us\"; \r\n$api=$client-\u003eunblockContact($chatId);\r\nprint_r($api);\r\n```\r\n\r\n## Check if number is WhatsApp user\r\n\r\n* **$chatId** : chatID for contact e.g 14155552671@c.us \r\n\r\n```php  \r\n$chatId=\"14155552671@c.us\"; \r\n$api=$client-\u003echeckContact($chatId);\r\nprint_r($api);\r\n```\r\n\r\n\r\n\r\n# Support\r\nUse **Issues** to contact me","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fultramsg%2Fwhatsapp-php-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fultramsg%2Fwhatsapp-php-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fultramsg%2Fwhatsapp-php-sdk/lists"}