{"id":1519,"date":"2022-03-07T08:12:39","date_gmt":"2022-03-07T08:12:39","guid":{"rendered":"https:\/\/blog.ultramsg.com\/%d0%ba%d0%b0%d0%ba-%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-python-webhook\/"},"modified":"2022-05-03T01:41:05","modified_gmt":"2022-05-03T01:41:05","slug":"%d0%ba%d0%b0%d0%ba-%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-python-webhook","status":"publish","type":"post","link":"https:\/\/blog.ultramsg.com\/ru\/%d0%ba%d0%b0%d0%ba-%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-python-webhook\/","title":{"rendered":"\u041a\u0430\u043a \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f WhatsApp \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e python \u0438 webhook"},"content":{"rendered":"\n<p><\/p>\n\n<h2 class=\"wp-block-heading\">\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435 <br\/><\/h2>\n\n<p>\u0412 \u044d\u0442\u043e\u043c \u0443\u0440\u043e\u043a\u0435 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \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 Python.<\/p>\n\n<h2 class=\"wp-block-heading\">\u0417\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438<\/h2>\n\n<h3 class=\"wp-block-heading\">\u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043d\u0433\u0440\u043e\u043a<\/h3>\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\/\" target=\"_blank\" rel=\"noreferrer noopener\">ngrok.<\/a> \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u043a\u0430\u0447\u0430\u0442\u044c ngrok <a href=\"https:\/\/ngrok.com\/download\" target=\"_blank\" rel=\"noreferrer noopener\">\u043e\u0442\u0441\u044e\u0434\u0430<\/a> .<\/p>\n\n<h3 class=\"wp-block-heading\">\u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043a\u043e\u043b\u0431\u0443<\/h3>\n\n<pre class=\"wp-block-code\"><code>pip install flask<\/code><\/pre>\n\n<p>\u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0440\u0430\u0437\u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0441\u0435\u0440\u0432\u0435\u0440 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430 FLASK.<br\/>FLASK \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0443\u0434\u043e\u0431\u043d\u043e \u043e\u0442\u0432\u0435\u0447\u0430\u0442\u044c \u043d\u0430 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0438\u0445.<\/p>\n\n<h2 class=\"wp-block-heading\">\u0428\u0430\u0433 1: \u0421\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u043d\u043e\u0432\u043e\u0435 \u0444\u043b\u044f\u0436\u043d\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435<\/h2>\n\n<p>\u041c\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0444\u0430\u0439\u043b: <strong>app.py<\/strong> \u0438 \u043f\u0438\u0448\u0435\u043c \u0432 \u043d\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434<\/p>\n\n<pre class=\"wp-block-code\"><code><code data-enlighter-language=\"python\" class=\"EnlighterJSRAW\">from flask import Flask, request, jsonify\nfrom test import Ultrawebhook\nimport json\n\napp = Flask(__name__)\n\n@app.route('\/', methods=&#91;'POST'])\ndef home():\n    if request.method == 'POST':\n        bot = Ultrawebhook(request.json)\n        return bot.processing()\n\nif(__name__) == '__main__':\n    app.run()<\/code><\/code><\/pre>\n\n<h2 class=\"wp-block-heading\">\u0428\u0430\u0433 2: \u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0432\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f<\/h2>\n\n<p>\u041c\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0444\u0430\u0439\u043b: <strong>test.py<\/strong> \u0438 \u043f\u0438\u0448\u0435\u043c \u0432 \u043d\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434<\/p>\n\n<pre class=\"wp-block-code\"><code><code data-enlighter-language=\"python\" class=\"EnlighterJSRAW\">import json\nimport requests\n\n\nclass Ultrawebhook():    \n    def __init__(self, json):\n        self.json = json\n        self.dict_messages = json&#91;'data']\n\n\n    def processing(self):\n        if self.dict_messages != &#91;]:\n            message = self.dict_messages\n            msg_from = message&#91;'from'].split()\n            msg_text = message&#91;'body'].split()\n            print(\"sender phone number : \" + msg_from&#91;0])\n            print(\"message : \" + msg_text&#91;0])\n            return ''\n<\/code><\/code><\/pre>\n\n<h2 class=\"wp-block-heading\">\u0428\u0430\u0433 3: \u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 \u043f\u0440\u043e\u0435\u043a\u0442<\/h2>\n\n<h3 class=\"wp-block-heading\">\u0421\u0442\u0430\u0440\u0442\u043e\u0432\u0430\u044f \u043a\u043e\u043b\u0431\u0430:<\/h3>\n\n<pre class=\"wp-block-code\"><code><code data-enlighter-language=\"powershell\" class=\"EnlighterJSRAW\">flask run<\/code><\/code><\/pre>\n\n<h3 class=\"wp-block-heading\">\u041d\u0430\u0447\u0430\u0442\u044c \u043d\u0433\u0440\u043e\u043a<\/h3>\n\n<p>\u0414\u043b\u044f Windows:<\/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>\u0414\u043b\u044f Mac:<\/p>\n\n<pre class=\"wp-block-code\"><code><code data-enlighter-language=\"powershell\" class=\"EnlighterJSRAW\">.\/ngrok http 5000<\/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, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n\n<pre class=\"wp-block-code\"><code><code data-enlighter-language=\"powershell\" class=\"EnlighterJSRAW\">https:\/\/7647-115-83-121-164.ngrok.io<\/code><\/code><\/pre>\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, \u043a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0440\u0438\u0441\u0443\u043d\u043a\u0435. <\/p>\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"612\" src=\"https:\/\/blog.ultramsg.com\/wp-content\/uploads\/2022\/03\/image-1024x612.png\" alt=\"&#x41F;&#x43E;&#x43B;&#x443;&#x447;&#x430;&#x439;&#x442;&#x435; &#x441;&#x43E;&#x43E;&#x431;&#x449;&#x435;&#x43D;&#x438;&#x44F; WhatsApp, &#x438;&#x441;&#x43F;&#x43E;&#x43B;&#x44C;&#x437;&#x443;&#x44F; python &#x438; webhook-ultramsg\" class=\"wp-image-1469\" title=\"\" srcset=\"https:\/\/blog.ultramsg.com\/wp-content\/uploads\/2022\/03\/image-1024x612.png 1024w, https:\/\/blog.ultramsg.com\/wp-content\/uploads\/2022\/03\/image-300x179.png 300w, https:\/\/blog.ultramsg.com\/wp-content\/uploads\/2022\/03\/image-768x459.png 768w, https:\/\/blog.ultramsg.com\/wp-content\/uploads\/2022\/03\/image.png 1432w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\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-preformatted\"><code data-enlighter-language=\"json\" class=\"EnlighterJSRAW\">{\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<h2 class=\"wp-block-heading\">\u0424\u0438\u043d\u043b\u0438: \u0442\u0435\u0441\u0442 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 WhatsApp \u043f\u0435\u0440\u0432\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435<\/h2>\n\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0442\u043f\u0440\u0430\u0432\u044c\u0442\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 WhatsApp \u043d\u0430 \u043d\u043e\u043c\u0435\u0440, \u043a \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u0432\u044b \u043f\u0440\u0438\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u0442\u0435 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440.<br\/>\u0411\u0443\u0434\u0435\u0442 \u0440\u0430\u0441\u043f\u0435\u0447\u0430\u0442\u0430\u043d \u043d\u043e\u043c\u0435\u0440 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u0435\u043b\u044f \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435.<\/p>\n\n<p>\u041f\u043e\u0437\u0434\u0440\u0430\u0432\u043b\u044f\u0435\u043c. \u0412\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u043f\u0435\u0440\u0432\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 WhatsApp.<\/p>\n\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u043f\u043e\u043b\u0443\u0447\u0438\u0432 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f WhatsApp, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043b\u0435\u0433\u043a\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0447\u0430\u0442-\u0431\u043e\u0442\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f Python \u0438 Ultramsg API.<\/p>\n\n<h2 class=\"wp-block-heading\" id=\"types-of-webhooks-to-use-with-whatsapp-api-ultramsg\">\u0422\u0438\u043f\u044b \u0432\u0435\u0431-\u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u0447\u0438\u043a\u043e\u0432 \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441 WhatsApp API \u0438 Ultramsg<\/h2>\n\n<ul class=\"wp-block-list\"><li><strong>webhook_message_received<\/strong> : \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f \u0432 \u0432\u0435\u0431-\u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u0447\u0438\u043a\u0430\u0445 \u043f\u0440\u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f.<\/li><li><strong>webhook_message_create<\/strong> : \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f \u0432 \u0432\u0435\u0431-\u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u0447\u0438\u043a\u0430\u0445 \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f.<\/li><li><strong>webhook_message_ack<\/strong> : \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0435 (\u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043e \u0438 \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043e) \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f \u0432 \u0432\u0435\u0431-\u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u0447\u0438\u043a\u0430\u0445.<\/li><\/ul>\n\n<p>\u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u0441 \u043f\u043e\u043b\u043d\u043e\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0435\u0439 \u043f\u043e <a href=\"https:\/\/docs.ultramsg.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">Whatsapp API<\/a> \u0438 <a href=\"https:\/\/blog.ultramsg.com\/whatsapp-api-by-ultramsg-faq\/\">\u0447\u0430\u0441\u0442\u043e \u0437\u0430\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u043c\u0438<\/a> \u0432\u043e\u043f\u0440\u043e\u0441\u0430\u043c\u0438.<a href=\"https:\/\/user.ultramsg.com\/\" target=\"_blank\" rel=\"noreferrer noopener\"><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0412 \u044d\u0442\u043e\u043c \u0443\u0440\u043e\u043a\u0435 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \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 &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"\u041a\u0430\u043a \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f WhatsApp \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e python \u0438 webhook\" class=\"read-more button\" href=\"https:\/\/blog.ultramsg.com\/ru\/%d0%ba%d0%b0%d0%ba-%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-python-webhook\/#more-1519\" aria-label=\"\u041f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u043e \u041a\u0430\u043a \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f WhatsApp \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e python \u0438 webhook\">Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":1508,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[132],"tags":[146,160,150,136],"class_list":["post-1519","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-api-whatsapp-ru","tag-146","tag-160","tag-150","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\/1519","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=1519"}],"version-history":[{"count":9,"href":"https:\/\/blog.ultramsg.com\/ru\/wp-json\/wp\/v2\/posts\/1519\/revisions"}],"predecessor-version":[{"id":2353,"href":"https:\/\/blog.ultramsg.com\/ru\/wp-json\/wp\/v2\/posts\/1519\/revisions\/2353"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ultramsg.com\/ru\/wp-json\/wp\/v2\/media\/1508"}],"wp:attachment":[{"href":"https:\/\/blog.ultramsg.com\/ru\/wp-json\/wp\/v2\/media?parent=1519"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ultramsg.com\/ru\/wp-json\/wp\/v2\/categories?post=1519"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ultramsg.com\/ru\/wp-json\/wp\/v2\/tags?post=1519"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}