{"id":1388,"date":"2022-03-02T15:13:28","date_gmt":"2022-03-02T15:13:28","guid":{"rendered":"https:\/\/blog.ultramsg.com\/%d0%bf%d0%be%d0%bb%d1%83%d1%87%d0%b0%d1%82%d1%8c-%d1%81%d0%be%d0%be%d0%b1%d1%89%d0%b5%d0%bd%d0%b8%d1%8f-whatsapp-%d1%81-%d0%bf%d0%be%d0%bc%d0%be%d1%89%d1%8c%d1%8e-php-and-webhook\/"},"modified":"2022-03-12T05:18:24","modified_gmt":"2022-03-12T05:18:24","slug":"%d0%bf%d0%be%d0%bb%d1%83%d1%87%d0%b0%d1%82%d1%8c-%d1%81%d0%be%d0%be%d0%b1%d1%89%d0%b5%d0%bd%d0%b8%d1%8f-whatsapp-%d1%81-%d0%bf%d0%be%d0%bc%d0%be%d1%89%d1%8c%d1%8e-php-and-webhook","status":"publish","type":"post","link":"https:\/\/blog.ultramsg.com\/ru\/%d0%bf%d0%be%d0%bb%d1%83%d1%87%d0%b0%d1%82%d1%8c-%d1%81%d0%be%d0%be%d0%b1%d1%89%d0%b5%d0%bd%d0%b8%d1%8f-whatsapp-%d1%81-%d0%bf%d0%be%d0%bc%d0%be%d1%89%d1%8c%d1%8e-php-and-webhook\/","title":{"rendered":"\u041f\u043e\u043b\u0443\u0447\u0430\u0439\u0442\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f WhatsApp \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e PHP \u0438 \u0432\u0435\u0431-\u0445\u0443\u043a\u0430"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"introduction\">\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h2>\n\n<p>\u0412 \u044d\u0442\u043e\u043c \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0435 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 WhatsApp \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c PHP.<\/p>\n\n<h2 class=\"wp-block-heading\" id=\"dependencies\">\u0417\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438<\/h2>\n\n<p>\u0434\u043b\u044f \u0446\u0435\u043b\u0435\u0439 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0441\u043b\u0443\u0436\u0431\u0430 \u0442\u0443\u043d\u043d\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f <a href=\"https:\/\/ngrok.com\/\" rel=\"nofollow noopener\" target=\"_blank\">ngrok.<\/a> \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u043a\u0430\u0447\u0430\u0442\u044c ngrok <a href=\"https:\/\/ngrok.com\/download\" data-type=\"URL\" data-id=\"https:\/\/ngrok.com\/download\" rel=\"nofollow noopener\" target=\"_blank\">\u043e\u0442\u0441\u044e\u0434\u0430<\/a> .<\/p>\n\n<h2 class=\"wp-block-heading\" id=\"example\">\u041f\u0440\u0438\u043c\u0435\u0440<\/h2>\n\n<p>\u042d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u0433\u0434\u0430 \u0441\u0435\u0440\u0432\u0435\u0440 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0442\u0435\u043b\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0432 \u0444\u0430\u0439\u043b log.txt.<\/p>\n\n<p>\u0422\u0435\u043b\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043f\u043e\u043b\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0432\u0435\u0431-\u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u0447\u0438\u043a\u0435, \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u0443\u044e \u0438\u0437 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 WhatsApp Ultramsg API.<\/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\">\u041e\u0431 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u0430<\/h2>\n\n<p>\u0421\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u0432\u044b\u0448\u0435 \u0444\u0430\u0439\u043b \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043a\u0430\u043a test.php \u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u0435 \u0435\u0433\u043e \u043d\u0430 \u0441\u0432\u043e\u0439 \u0441\u0435\u0440\u0432\u0435\u0440. URL-\u0430\u0434\u0440\u0435\u0441 Webhook \u0431\u0443\u0434\u0435\u0442:<\/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\">\u041e \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0441 ngrok<\/h2>\n\n<p>\u0421\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u0432\u044b\u0448\u0435 \u0444\u0430\u0439\u043b \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043a\u0430\u043a test.php \u043d\u0430 \u0432\u0430\u0448\u0435\u043c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u043c \u0445\u043e\u0441\u0442\u0435, \u0438 URL-\u0430\u0434\u0440\u0435\u0441 \u0431\u0443\u0434\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c:<\/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>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043d\u0433\u0440\u043e\u043a:<\/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>\u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0432\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0443\u0432\u0438\u0434\u0435\u0442\u044c<br\/>*.ngrok.io URL-\u0430\u0434\u0440\u0435\u0441.<br\/>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 :<br\/>https:\/\/7647-115-83-121-164.ngrok.io<br\/>\u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0445\u043e\u0441\u0442 \u043d\u0430<br\/>URL-\u0430\u0434\u0440\u0435\u0441 ngrok.io<br\/>URL \u0431\u0443\u0434\u0435\u0442:<br\/>https:\/\/7647-115-83-121-164.ngrok.io\/webhook.php<\/p>\n\n<h2 class=\"wp-block-heading\" id=\"what-s-next\">\u0427\u0442\u043e \u0434\u0430\u043b\u044c\u0448\u0435?<\/h2>\n\n<p>\u0432\u0441\u0442\u0430\u0432\u044c\u0442\u0435 \u0441\u0432\u043e\u0439 URL-\u0430\u0434\u0440\u0435\u0441 \u0432 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430.<br\/>\u0422\u0435\u043f\u0435\u0440\u044c \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0432\u0435\u0431-\u0445\u0443\u043a\u0438, \u0438 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0438\u0445 \u0432 \u0444\u0430\u0439\u043b\u0435 log.txt.<\/p>\n\n<h2 class=\"wp-block-heading\" id=\"example-json-response\">\u041f\u0420\u0418\u041c\u0415\u0420 \u041e\u0422\u0412\u0415\u0422\u0410 \u0412 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\">\u041f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u0441\u0441\u044b\u043b\u043a\u0438<\/h2>\n\n<ul class=\"wp-block-list\"><li><span style=\"font-family: -apple-system, system-ui, BlinkMacSystemFont, \" segoe=\"\" ui=\"\" helvetica=\"\" arial=\"\" sans-serif=\"\" color=\"\" emoji=\"\" symbol=\"\">\u041f\u043e\u043b\u043d\u0430\u044f<\/span> <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\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u043f\u043e API Whatsapp<\/a> <span style=\"font-family: -apple-system, system-ui, BlinkMacSystemFont, \" segoe=\"\" ui=\"\" helvetica=\"\" arial=\"\" sans-serif=\"\" color=\"\" emoji=\"\" symbol=\"\">.<\/span><\/li><li>\u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f <a href=\"https:\/\/blog.ultramsg.com\/ru\/%d0%be%d1%82%d0%bf%d1%80%d0%b0%d0%b2%d0%b8%d1%82%d1%8c-whatsapp-%d1%81%d0%be%d0%be%d0%b1%d1%89%d0%b5%d0%bd%d0%b8%d0%b5-%d1%87%d0%b5%d1%80%d0%b5%d0%b7-whatsapp-api-%d0%b8%d1%81%d0%bf%d0%be%d0%bb%d1%8c\/\">API WhatsApp<\/a> \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e PHP.<\/li><\/ul>\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0412 \u044d\u0442\u043e\u043c \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0435 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 WhatsApp \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c PHP. &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"\u041f\u043e\u043b\u0443\u0447\u0430\u0439\u0442\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f WhatsApp \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e PHP \u0438 \u0432\u0435\u0431-\u0445\u0443\u043a\u0430\" class=\"read-more button\" href=\"https:\/\/blog.ultramsg.com\/ru\/%d0%bf%d0%be%d0%bb%d1%83%d1%87%d0%b0%d1%82%d1%8c-%d1%81%d0%be%d0%be%d0%b1%d1%89%d0%b5%d0%bd%d0%b8%d1%8f-whatsapp-%d1%81-%d0%bf%d0%be%d0%bc%d0%be%d1%89%d1%8c%d1%8e-php-and-webhook\/#more-1388\" aria-label=\"\u041f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u043e \u041f\u043e\u043b\u0443\u0447\u0430\u0439\u0442\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f WhatsApp \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e PHP \u0438 \u0432\u0435\u0431-\u0445\u0443\u043a\u0430\">Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":1213,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[132],"tags":[133,146,136],"class_list":["post-1388","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-api-whatsapp-ru","tag-php-ru","tag-146","tag-136","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\/ru\/wp-json\/wp\/v2\/posts\/1388","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ultramsg.com\/ru\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ultramsg.com\/ru\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ultramsg.com\/ru\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ultramsg.com\/ru\/wp-json\/wp\/v2\/comments?post=1388"}],"version-history":[{"count":4,"href":"https:\/\/blog.ultramsg.com\/ru\/wp-json\/wp\/v2\/posts\/1388\/revisions"}],"predecessor-version":[{"id":1802,"href":"https:\/\/blog.ultramsg.com\/ru\/wp-json\/wp\/v2\/posts\/1388\/revisions\/1802"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ultramsg.com\/ru\/wp-json\/wp\/v2\/media\/1213"}],"wp:attachment":[{"href":"https:\/\/blog.ultramsg.com\/ru\/wp-json\/wp\/v2\/media?parent=1388"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ultramsg.com\/ru\/wp-json\/wp\/v2\/categories?post=1388"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ultramsg.com\/ru\/wp-json\/wp\/v2\/tags?post=1388"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}