{"id":651,"date":"2022-02-08T18:02:57","date_gmt":"2022-02-08T18:02:57","guid":{"rendered":"https:\/\/blog.ultramsg.com\/receive-whatsapp-messages-using-php-and-webhook\/"},"modified":"2022-03-12T05:15:51","modified_gmt":"2022-03-12T05:15:51","slug":"%d8%a7%d8%b3%d8%aa%d9%82%d8%a8%d8%a7%d9%84-%d8%b1%d8%b3%d8%a7%d8%a6%d9%84-%d8%a7%d9%84%d9%88%d8%a7%d8%aa%d8%b3-%d8%a7%d8%a8-whatsapp-api-and-webhook","status":"publish","type":"post","link":"https:\/\/blog.ultramsg.com\/ar\/%d8%a7%d8%b3%d8%aa%d9%82%d8%a8%d8%a7%d9%84-%d8%b1%d8%b3%d8%a7%d8%a6%d9%84-%d8%a7%d9%84%d9%88%d8%a7%d8%aa%d8%b3-%d8%a7%d8%a8-whatsapp-api-and-webhook\/","title":{"rendered":"\u0627\u0633\u062a\u0642\u0628\u0627\u0644 \u0631\u0633\u0627\u0626\u0644 WhatsApp \u0628\u0627\u0633\u062a\u062e\u062f\u0627\u0645 PHP \u0648 webhook"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"introduction\">\u0645\u0642\u062f\u0645\u0629<\/h2>\n\n<p>\u0641\u064a \u0647\u0630\u0627 \u0627\u0644\u0645\u0642\u0627\u0644 \u060c \u0633\u0646\u0646\u0634\u0626 \u0635\u0641\u062d\u0629 \u0644\u0644\u062a\u0639\u0627\u0645\u0644 \u0645\u0639 \u0631\u0633\u0627\u0626\u0644 WhatsApp \u0627\u0644\u0648\u0627\u0631\u062f\u0629 \u0628\u0627\u0633\u062a\u062e\u062f\u0627\u0645 PHP.<\/p>\n\n<h2 class=\"wp-block-heading\" id=\"dependencies\">Dependencies<\/h2>\n\n<p>\u0644\u0623\u063a\u0631\u0627\u0636 \u0627\u0644\u062a\u062c\u0631\u0628\u0629 \u0628\u0627\u0644\u0633\u064a\u0631\u0641\u0631 \u0627\u0644\u0645\u062d\u0644\u064a \u0633\u0646\u062d\u062a\u0627\u062c \u0644\u062e\u062f\u0645\u0629 tunneling \u0648 \u0641\u064a \u0647\u0630\u0627 \u0627\u0644\u062f\u0631\u0633 \u0633\u0646\u0633\u062a\u062e\u062f\u0645 ngrok \u064a\u0645\u0643\u0646\u0643 \u062a\u062d\u0645\u064a\u0644 <a href=\"https:\/\/ngrok.com\/\" rel=\"nofollow noopener\" target=\"_blank\">ngrok<\/a> \u0645\u0646 <a href=\"https:\/\/ngrok.com\/download\" data-type=\"URL\" data-id=\"https:\/\/ngrok.com\/download\" rel=\"nofollow noopener\" target=\"_blank\">\u0647\u0646\u0627<\/a> .<\/p>\n\n<h2 class=\"wp-block-heading\" id=\"example\">\u0645\u062b\u0627\u0644<\/h2>\n\n<p>\u0647\u0630\u0627 \u0645\u062b\u0627\u0644 \u0628\u0633\u064a\u0637 \u060c \u062d\u064a\u062b \u064a\u0642\u0648\u0645 \u0627\u0644\u0633\u064a\u0631\u0641\u0631 \u0628\u062a\u062e\u0632\u064a\u0646 \u0627\u0644\u0631\u0633\u0627\u0626\u0644 \u0627\u0644\u0648\u0627\u0631\u062f\u0629 \u0641\u064a \u0645\u0644\u0641 log.txt file .<\/p>\n\n<p>\u0633\u064a\u062d\u062a\u0648\u064a \u0627\u0644\u0637\u0644\u0628 \u0639\u0644\u0649 \u062c\u0645\u064a\u0639 \u0645\u0639\u0644\u0648\u0645\u0627\u062a \u0627\u0644\u0648\u064a\u0628 \u0647\u0648\u0643 \u0627\u0644\u0645\u0631\u0633\u0644 \u0645\u0646 \u062c\u0647\u0627\u0632 \u0627\u0644\u0648\u0627\u062a\u0633 \u0627\u0628 \u0627\u0644\u062e\u0627\u0635 \u0628\u0627\u0644\u062a\u0631\u0627\u0645\u0633\u062c<\/p>\n\n<pre class=\"wp-block-code\"><code><code data-enlighter-language=\"php\" class=\"EnlighterJSRAW\">$data = file_get_contents(\"php:\/\/input\");\n$event = json_decode($data, true);\nif(isset($event)){\n\t\/\/Here, you now have event and can process them how you like e.g Add to the database or generate a response\n\t$file = 'log.txt';  \n\t$data =json_encode($event).\"\\n\";  \n\tfile_put_contents($file, $data, FILE_APPEND | LOCK_EX);\n<\/code>}<\/code><\/pre>\n\n<h2 class=\"wp-block-heading\" id=\"on-server-usage\">\u0641\u064a \u062d\u0627\u0644\u0629 \u0627\u0644\u0625\u0633\u062a\u062e\u062f\u0627\u0645 \u0639\u0644\u0649 \u0627\u0644\u0633\u064a\u0631\u0641\u0631<\/h2>\n\n<p>\u0627\u062d\u0641\u0638 \u0645\u0644\u0641 \u0627\u0644\u0645\u062b\u0627\u0644 \u0623\u0639\u0644\u0627\u0647 webhook.php \u0648\u0642\u0645 \u0628\u0631\u0641\u0639\u0647 \u0639\u0644\u0649 \u0627\u0644\u0633\u064a\u0631\u0641\u0631 \u0627\u0644\u062e\u0627\u0635 \u0628\u0643 \u0633\u064a\u0643\u0648\u0646 \u0647\u0648 \u0639\u0646\u0648\u0627\u0646 URL \u0627\u0644\u062e\u0627\u0635 \u0628\u0640 Webhook :<\/p>\n\n<pre class=\"wp-block-code\"><code><a href=\"http:\/\/your-server\/webhook.php\"><code data-enlighter-language=\"powershell\" class=\"EnlighterJSRAW\">http:\/\/your-server\/test.php<\/code><\/a><\/code><\/pre>\n\n<h2 class=\"wp-block-heading\" id=\"on-local-usage-with-ngrok\">\u0641\u064a \u062d\u0627\u0644\u0629 \u0627\u0644\u0625\u0633\u062a\u062e\u062f\u0627\u0645 \u0639\u0644\u0649 \u0633\u064a\u0631\u0641\u0631 \u0645\u062d\u0644\u064a<\/h2>\n\n<p>\u0627\u062d\u0641\u0638 \u0645\u0644\u0641 \u0627\u0644\u0645\u062b\u0627\u0644 \u0623\u0639\u0644\u0627\u0647 webhook.php \u0648\u0642\u0645 \u0628\u0648\u0636\u0639\u0647 \u0639\u0644\u0649 \u0627\u0644\u0633\u064a\u0631\u0641\u0631 \u0627\u0644\u0645\u062d\u0644\u064a \u0648 \u0633\u064a\u0643\u0648\u0646 \u0647\u0648 \u0639\u0646\u0648\u0627\u0646 URL \u0627\u0644\u062e\u0627\u0635 \u0628\u0640 Webhook :<\/p>\n\n<pre class=\"wp-block-code\"><code><code data-enlighter-language=\"powershell\" class=\"EnlighterJSRAW\">http:\/\/localhost\/test.php<\/code><\/code><\/pre>\n\n<p>\u062a\u0634\u063a\u064a\u0644 ngrok<\/p>\n\n<pre class=\"wp-block-code\"><code><code data-enlighter-language=\"powershell\" class=\"EnlighterJSRAW\">ngrok http 80<\/code><\/code><\/pre>\n\n<p>\u0628\u0639\u062f \u0630\u0644\u0643 \u060c \u064a\u062c\u0628 \u0623\u0646 \u062a\u0634\u0627\u0647\u062f<br\/>*.ngrok.io URL.<br\/>\u0645\u062b\u0644\u0627\u064b :<br\/>https:\/\/7647-115-83-121-164.ngrok.io<br\/>\u0627\u0633\u062a\u0628\u062f\u0644 localhost \u0628\u0640<br\/>ngrok.io URL<br\/>\u0633\u064a\u0643\u0648\u0646 \u0627\u0631\u0628\u0637 \u0627\u0644\u0648\u064a\u0628 \u0647\u0648\u0643:<br\/>https:\/\/7647-115-83-121-164.ngrok.io\/webhook.php<\/p>\n\n<h2 class=\"wp-block-heading\" id=\"what-s-next\">\u0645\u0627\u0630\u0627 \u0628\u0639\u062f\u061f<\/h2>\n\n<p>\u0627\u0644\u0635\u0642 \u0639\u0646\u0648\u0627\u0646 URL \u0627\u0644\u062e\u0627\u0635 \u0628\u0640 Webhook \u0641\u064a \u0625\u0639\u062f\u0627\u062f\u0627\u062a \u0627\u0644\u062c\u0647\u0627\u0632 .<br\/>\u0627\u0644\u0623\u0646 \u064a\u062c\u0628 \u0627\u0646 \u062a\u0643\u0648\u0646 \u0642\u0627\u062f\u0631 \u0639\u0644\u0649 \u0627\u0633\u062a\u0642\u0628\u0627\u0644 \u0627\u0644\u0648\u064a\u0628 \u0647\u0648\u0643 \u0648 \u0633\u062a\u0634\u0627\u0647\u062f\u0647\u0645 \u062c\u0645\u064a\u0639\u0627\u064b \u0641\u064a log.txt file .<\/p>\n\n<h2 class=\"wp-block-heading\" id=\"example-json-response\">\u0645\u062b\u0627\u0644 \u0639\u0646 \u0627\u0644\u0631\u062f \u0628\u0635\u064a\u063a\u0629 Json <\/h2>\n\n<pre class=\"wp-block-code\"><code>{\n  \"event_type\": \"message_received\",\n  \"instanceId\": \"90\",\n  \"data\": {\n    \"id\": \"false_10172127174@c.us_7ECAED9EB68D3474BE591443134C2E3F\",\n    \"from\": \"10172127174@c.us\",\n    \"to\": \"10172127175@c.us\",\n    \"ack\": \"pending\",\n    \"type\": \"chat\",\n    \"body\": \"I can't send a message using php code\\nCan you help me\",\n    \"fromMe\": false,\n    \"isForwarded\": false,\n    \"time\": 1643311467\n  }\n}<\/code><\/pre>\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"Receive WhatsApp messages using PHP | WhatsApp api Webhook\" width=\"1200\" height=\"675\" src=\"https:\/\/www.youtube.com\/embed\/TfQOclLMIng?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n<h2 class=\"wp-block-heading\" id=\"useful-links\">\u0631\u0648\u0627\u0628\u0637 \u0645\u0641\u064a\u062f\u0629<\/h2>\n\n<ul class=\"wp-block-list\"><li><a style=\"font-family: -apple-system, system-ui, BlinkMacSystemFont, \" segoe=\"\" ui=\"\" helvetica=\"\" arial=\"\" sans-serif=\"\" color=\"\" emoji=\"\" symbol=\"\" href=\"https:\/\/docs.ultramsg.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">\u0648\u062b\u0627\u0626\u0642 Whatsapp API<\/a> <span style=\"font-family: -apple-system, system-ui, BlinkMacSystemFont, \" segoe=\"\" ui=\"\" helvetica=\"\" arial=\"\" sans-serif=\"\" color=\"\" emoji=\"\" symbol=\"\">\u0627\u0644\u0643\u0627\u0645\u0644\u0629<\/span> <span style=\"font-family: -apple-system, system-ui, BlinkMacSystemFont, \" segoe=\"\" ui=\"\" helvetica=\"\" arial=\"\" sans-serif=\"\" color=\"\" emoji=\"\" symbol=\"\">.<\/span><\/li><li>\u0627\u0631\u0633\u0627\u0644 \u0631\u0633\u0627\u0626\u0644 <a href=\"https:\/\/blog.ultramsg.com\/ar\/%d9%88%d8%a7%d8%aa%d8%b3-%d8%a7%d8%a8-whatsapp-api-using-php\/\">WhatsApp API<\/a> \u0628\u0648\u0627\u0633\u0637\u0629 \u0644\u063a\u0629 PHP .<\/li><\/ul>\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0645\u0642\u062f\u0645\u0629 \u0641\u064a \u0647\u0630\u0627 \u0627\u0644\u0645\u0642\u0627\u0644 \u060c \u0633\u0646\u0646\u0634\u0626 \u0635\u0641\u062d\u0629 \u0644\u0644\u062a\u0639\u0627\u0645\u0644 \u0645\u0639 \u0631\u0633\u0627\u0626\u0644 WhatsApp \u0627\u0644\u0648\u0627\u0631\u062f\u0629 \u0628\u0627\u0633\u062a\u062e\u062f\u0627\u0645 PHP. Dependencies &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"\u0627\u0633\u062a\u0642\u0628\u0627\u0644 \u0631\u0633\u0627\u0626\u0644 WhatsApp \u0628\u0627\u0633\u062a\u062e\u062f\u0627\u0645 PHP \u0648 webhook\" class=\"read-more button\" href=\"https:\/\/blog.ultramsg.com\/ar\/%d8%a7%d8%b3%d8%aa%d9%82%d8%a8%d8%a7%d9%84-%d8%b1%d8%b3%d8%a7%d8%a6%d9%84-%d8%a7%d9%84%d9%88%d8%a7%d8%aa%d8%b3-%d8%a7%d8%a8-whatsapp-api-and-webhook\/#more-651\" aria-label=\"Read more about \u0627\u0633\u062a\u0642\u0628\u0627\u0644 \u0631\u0633\u0627\u0626\u0644 WhatsApp \u0628\u0627\u0633\u062a\u062e\u062f\u0627\u0645 PHP \u0648 webhook\">Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":416,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[26,27,40],"class_list":["post-651","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category---api","tag-php-ar","tag-webhook-ar","tag-40","infinite-scroll-item","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-25","no-featured-image-padding"],"_links":{"self":[{"href":"https:\/\/blog.ultramsg.com\/ar\/wp-json\/wp\/v2\/posts\/651","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ultramsg.com\/ar\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ultramsg.com\/ar\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ultramsg.com\/ar\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ultramsg.com\/ar\/wp-json\/wp\/v2\/comments?post=651"}],"version-history":[{"count":8,"href":"https:\/\/blog.ultramsg.com\/ar\/wp-json\/wp\/v2\/posts\/651\/revisions"}],"predecessor-version":[{"id":1800,"href":"https:\/\/blog.ultramsg.com\/ar\/wp-json\/wp\/v2\/posts\/651\/revisions\/1800"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ultramsg.com\/ar\/wp-json\/wp\/v2\/media\/416"}],"wp:attachment":[{"href":"https:\/\/blog.ultramsg.com\/ar\/wp-json\/wp\/v2\/media?parent=651"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ultramsg.com\/ar\/wp-json\/wp\/v2\/categories?post=651"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ultramsg.com\/ar\/wp-json\/wp\/v2\/tags?post=651"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}