{"id":21806158,"url":"https://github.com/adrianvillamayor/whatsapp-api","last_synced_at":"2025-04-13T20:05:47.552Z","repository":{"id":59377092,"uuid":"536932678","full_name":"AdrianVillamayor/Whatsapp-Api","owner":"AdrianVillamayor","description":"WhatsApp-Api is a lightweight library to easily interact with cloud APIs of the WhatsApp Business Platform.","archived":false,"fork":false,"pushed_at":"2024-04-26T08:35:37.000Z","size":44,"stargazers_count":22,"open_issues_count":0,"forks_count":7,"subscribers_count":6,"default_branch":"main","last_synced_at":"2024-11-24T17:40:54.260Z","etag":null,"topics":["lightweight","php","whatsapp","whatsapp-api"],"latest_commit_sha":null,"homepage":"","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/AdrianVillamayor.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}},"created_at":"2022-09-15T08:27:43.000Z","updated_at":"2024-08-25T18:56:35.000Z","dependencies_parsed_at":"2024-04-26T09:42:09.672Z","dependency_job_id":"1bc392a9-fe9d-4e94-9085-481e0130b4ea","html_url":"https://github.com/AdrianVillamayor/Whatsapp-Api","commit_stats":{"total_commits":37,"total_committers":1,"mean_commits":37.0,"dds":0.0,"last_synced_commit":"4f93d5375cc3f1bc2fca46ac83b7ac09c1b3b01e"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AdrianVillamayor%2FWhatsapp-Api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AdrianVillamayor%2FWhatsapp-Api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AdrianVillamayor%2FWhatsapp-Api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AdrianVillamayor%2FWhatsapp-Api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AdrianVillamayor","download_url":"https://codeload.github.com/AdrianVillamayor/Whatsapp-Api/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226745324,"owners_count":17675027,"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":["lightweight","php","whatsapp","whatsapp-api"],"created_at":"2024-11-27T12:18:06.101Z","updated_at":"2024-11-27T12:18:06.677Z","avatar_url":"https://github.com/AdrianVillamayor.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Whatsapp-Api\n\n[![Latest Stable Version](http://img.shields.io/packagist/v/adrii/whatsapp-api.svg)](https://packagist.org/packages/adrii/whatsapp-api)\n[![Total Downloads](http://img.shields.io/packagist/dt/adrii/whatsapp-api.svg)](https://packagist.org/packages/adrii/whatsapp-api)\n[![License](http://img.shields.io/packagist/l/adrii/whatsapp-api.svg)](https://packagist.org/packages/adrii/whatsapp-api)\n\nWhatsApp-Api is a lightweight library to easily interact with cloud APIs of the [WhatsApp Business Platform](https://developers.facebook.com/docs/whatsapp/business-management-api/get-started).\n\n\n\n| INDEX |\n|-------|\n| [Installation](https://github.com/AdrianVillamayor/Whatsapp-Api#installation)   |\n| [Configutation](https://github.com/AdrianVillamayor/Whatsapp-Api#configutation) |\n| [Webhook](https://github.com/AdrianVillamayor/Whatsapp-Api#webhook)             |\n| [Messages](https://github.com/AdrianVillamayor/Whatsapp-Api#messages)           |\n| [License](https://github.com/AdrianVillamayor/Whatsapp-Api#license)             |\n \n\n## Installation\n\nUse [Composer](https://getcomposer.org/) to install the library.\n\n```bash\ncomposer require adrii/whatsapp-api\n```\n\n### Composer\n```php\nuse Adrii\\Whatsapp\\Whatsapp;\n```\n\n## Configutation\n\n```php\n$graph_version    = \"v15.0\";\n$phone_number_id  = \"{phone_number_id}\";\n$access_token     = \"{access_token}\";\n$recipient_id     = \"{recipient_id}\";\n\n$ws = new Whatsapp($phone_number_id, $access_token, $graph_version);\n```\n\u003c/br\u003e\n\n## Webhook\nTo be alerted when you receive a message or when the status of a message changes, you need to set up a webhook connection point for your app.\n\nThis method handles the entire connection request on its own.\nThe access_token is used to validate the connection.\n\n```php\n$ws-\u003ewebhook()-\u003econnect($_GET);\n```\n\u003c/br\u003e\n\n## Messages\n\n| Status | Type  |\n| ------ | ----------------------------------------------------------------------------- |\n|   ✅   | [Text](https://github.com/AdrianVillamayor/Whatsapp-Api#text)                 |\n|   ✅   | [Template](https://github.com/AdrianVillamayor/Whatsapp-Api#template)         |\n|   ✅   | [Location](https://github.com/AdrianVillamayor/Whatsapp-Api#location)         |\n|   ✅   | [Contact](https://github.com/AdrianVillamayor/Whatsapp-Api#contact)           |\n|   ✅   | [Media](https://github.com/AdrianVillamayor/Whatsapp-Api#media)               |\n|   ✅   | [Interactive](https://github.com/AdrianVillamayor/Whatsapp-Api#interactive)   |\n\n### Text\nSend basic text (emojis allowed).\n```php\n$ws-\u003esend_message()-\u003etext(\"Aloha 🍍\", $recipient_id);\n```\n\n### Template\nSend message templates defined in the Meta manager.\n```php\n$ws-\u003esend_message()-\u003etemplate(\"hello_world\", $recipient_id);\n```\n\nSend message templates defined in the Meta manager with parameters\n```php\n$component_header = array(\n    \"type\" =\u003e \"header\",\n    \"parameters\" =\u003e array(\n        array(\n            \"type\" =\u003e \"image\",\n            \"image\" =\u003e array(\n                \"link\" =\u003e \"https://avatars.githubusercontent.com/u/29653964?v=4\"\n            )\n        ),\n    )\n);\n\n$component_body = array(\n    \"type\" =\u003e \"body\",\n    \"parameters\" =\u003e array(\n        array(\n            \"type\" =\u003e \"text\",\n            \"text\" =\u003e \"Adrii 🍍\"\n        )\n    )\n);\n\n$component_button = array(\n    \"type\"      =\u003e \"button\",\n    \"sub_type\"  =\u003e \"url\",\n    \"index\"     =\u003e 0,\n    \"parameters\" =\u003e array(\n        array(\n            \"type\" =\u003e \"text\",\n            \"text\" =\u003e \"https://github.com/AdrianVillamayor/Whatsapp-Api\"\n        )\n    )\n);\n\n$ws-\u003esend_message()-\u003eaddComponent($component_header, $component_body, $component_button);\n\n$response = $ws-\u003esend_message()-\u003etemplate(\"sample_purchase_feedback\", $recipient_id);\n```\n\n### Location\n\nSends a location, through a longitude, latitude and an address.\n```php\n$ws-\u003esend_message()-\u003elocation(\"41.403191\", \"2.174840\", \"La Sagrada Família\", \"C/ De Mallorca, 401, 08013 Barcelona\", $recipient_id);\n```\n\n### Contact\n\nSend a contact message\n\nThe name is the only required parameter, the other data are optional.\n```php\n    $contact = array(\n        \"addresses\" =\u003e array(\n            array(\n                \"city\"          =\u003e \"city name\",\n                \"country\"       =\u003e \"country name\",\n                \"country_code\"  =\u003e \"code\",\n                \"state\"         =\u003e \"Contact's State\",\n                \"street\"        =\u003e \"Contact's Street\",\n                \"type\"          =\u003e \"Contact's Address Type\",\n                \"zip\"           =\u003e \"Contact's Zip Code\"\n            )\n        ),\n\n        \"birthday\" =\u003e \"14-02-1997\",\n        \"emails\" =\u003e array(\n            array(\n                \"email\" =\u003e \"email\",\n                \"type\" =\u003e \"HOME\"\n            ),\n            array(\n                \"email\" =\u003e \"email\",\n                \"type\" =\u003e \"WORK\"\n            )\n        ),\n        \"name\" =\u003e array(\n            \"formatted_name\" =\u003e \"formatted name value\",\n            \"middle_name\" =\u003e \"last name value\",\n        ),\n        \"phones\" =\u003e array(\n            array(\n                \"phone\" =\u003e \"654034823\",\n                \"type\" =\u003e \"MAIN\"\n            ),\n            array(\n                \"phone\" =\u003e \"Phone number\",\n                \"type\" =\u003e \"HOME\"\n            ),\n            array(\n                \"phone\" =\u003e \"Phone number\",\n                \"type\" =\u003e \"WORK\"\n            )\n        ),\n        \"urls\" =\u003e array(\n            array(\n                \"url\" =\u003e \"some url\",\n                \"type\" =\u003e \"WORK\"\n            )\n        )\n    );\n\n\n$ws-\u003esend_message()-\u003eaddContact($contact);\n\n$response = $ws-\u003esend_message()-\u003econtact($recipient_id);\n\n```\n\nYou can concatenate as many contacts as you want\n```php\n$ws-\u003esend_message()-\u003eaddContact($contact_0, $contact_1, ...);\n```\n\n### Media\n\nSend a media, as a link or id\n```php\n$ws-\u003esend_message()-\u003emedia(\"image\", \"https://avatars.githubusercontent.com/u/29653964?v=4\", $recipient_id);\n\n$ws-\u003esend_message()-\u003emedia(\"video\", \"https://file-examples.com/storage/fe4658769b6331540b05587/2017/04/file_example_MP4_480_1_5MG.mp4\", $recipient_id);\n\n$ws-\u003esend_message()-\u003emedia(\"document\", \"https://file-examples.com/storage/fe4658769b6331540b05587/2017/10/file-sample_150kB.pdf\", $recipient_id);\n\n$ws-\u003esend_message()-\u003emedia(\"audio\", \"https://file-examples.com/storage/fe4658769b6331540b05587/2017/11/file_example_MP3_700KB.mp3\", $recipient_id);\n\n$ws-\u003esend_message()-\u003emedia(\"sticker\", \"https://img-03.stickers.cloud/packs/210a9e68-b249-405f-8ea1-9af015ef074a/webp/c5b7bded-e0f0-4f79-86aa-ffd825aba680.webp\", $recipient_id);\n```\n\nDescribes the specified image or video media with caption.\n```php\n$ws-\u003esend_message()-\u003emedia(\"image\", \"https://avatars.githubusercontent.com/u/29653964?v=4\", $recipient_id, \"individual\", true, \"your-image-caption-to-be-sent\");\n\n$ws-\u003esend_message()-\u003emedia(\"video\", \"https://file-examples.com/storage/fe4658769b6331540b05587/2017/04/file_example_MP4_480_1_5MG.mp4\", $recipient_id, \"individual\", true, \"your-video-caption-to-be-sent\");\n```\n\nDescribes the filename for the specific document.\n```php\n$ws-\u003esend_message()-\u003emedia(\"document\", \"https://file-examples.com/storage/fe4658769b6331540b05587/2017/10/file-sample_150kB.pdf\", $recipient_id, \"individual\", true, null, \"example_filename.pdf\");\n```\n\n### Interactive\n\nSend an interactive message with reply buttons\n```php\n$button = [\n        \"header\" =\u003e \"Header\",\n        \"body\"   =\u003e \"Body\",\n        \"footer\" =\u003e \"Footer\",\n        \"action\" =\u003e [\n            \"buttons\" =\u003e [\n                [\n                    \"type\" =\u003e \"reply\",\n                    \"reply\" =\u003e [\n                        \"id\" =\u003e \"UNIQUE_BUTTON_ID_1\",\n                        \"title\" =\u003e \"BUTTON_TITLE_1\"\n                    ]\n                ],\n                [\n                    \"type\" =\u003e \"reply\",\n                    \"reply\" =\u003e [\n                        \"id\" =\u003e \"UNIQUE_BUTTON_ID_2\",\n                        \"title\" =\u003e \"BUTTON_TITLE_2\"\n                    ]\n                ]\n            ]\n        ]\n    ];\n\n$ws-\u003esend_message()-\u003einteractive($button, $recipient_id, \"button\");\n\n```\n\nSend an interactive message with list of buttons\n```php\n$list = [\n    \"header\" =\u003e \"Test Header\",\n    \"body\"   =\u003e \"Test Body\",\n    \"footer\" =\u003e \"Test Footer\",\n    \"action\" =\u003e [\n        \"button\" =\u003e \"BUTTON_TEXT\",\n        \"sections\" =\u003e [\n            [\n                \"title\" =\u003e \"SECTION_1_TITLE\",\n                \"rows\" =\u003e\n                [\n                    [\n                        \"id\" =\u003e \"SECTION_1_ROW_1_ID\",\n                        \"title\" =\u003e \"SECTION_1_ROW_1_TITLE\",\n                        \"description\" =\u003e \"SECTION_1_ROW_1_DESCRIPTION\"\n                    ],\n                    [\n                        \"id\" =\u003e \"SECTION_1_ROW_2_ID\",\n                        \"title\" =\u003e \"SECTION_1_ROW_2_TITLE\",\n                        \"description\" =\u003e \"SECTION_1_ROW_2_DESCRIPTION\"\n                    ]\n                ]\n            ],\n            [\n                \"title\" =\u003e \"SECTION_2_TITLE\",\n                \"rows\" =\u003e [\n                    [\n                        \"id\" =\u003e \"SECTION_2_ROW_1_ID\",\n                        \"title\" =\u003e \"SECTION_2_ROW_1_TITLE\",\n                        \"description\" =\u003e \"SECTION_2_ROW_1_DESCRIPTION\"\n                    ],\n                    [\n                        \"id\" =\u003e \"SECTION_2_ROW_2_ID\",\n                        \"title\" =\u003e \"SECTION_2_ROW_2_TITLE\",\n                        \"description\" =\u003e \"SECTION_2_ROW_2_DESCRIPTION\"\n                    ]\n                ]\n            ]\n        ]\n    ]\n];\n\n$ws-\u003esend_message()-\u003einteractive($list, $recipient_id, \"list\");\n\n```\n\n\u003e ### [Data examples for each message](https://developers.facebook.com/docs/whatsapp/on-premises/webhooks/inbound#mentions)\n\n\u003c/br\u003e\n\n# Contributing\nPull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.\n\nPlease make sure to update tests as appropriate.\n\n# License\n[MIT](https://github.com/AdrianVillamayor/Whatsapp-Api/blob/master/LICENSE)\n\n### Thanks for your help! 🎉\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadrianvillamayor%2Fwhatsapp-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadrianvillamayor%2Fwhatsapp-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadrianvillamayor%2Fwhatsapp-api/lists"}