{"id":1907,"date":"2022-03-12T19:42:13","date_gmt":"2022-03-12T19:42:13","guid":{"rendered":"https:\/\/blog.ultramsg.com\/%d1%81%d0%b4%d0%b5%d0%bb%d0%b0%d1%82%d1%8c-whatsapp-%d1%87%d0%b0%d1%82-%d0%b1%d0%be%d1%82-%d0%b8%d1%81%d0%bf%d0%be%d0%bb%d1%8c%d0%b7%d1%83%d1%8f-python-ultramsg\/"},"modified":"2022-03-12T19:51:46","modified_gmt":"2022-03-12T19:51:46","slug":"%d1%81%d0%b4%d0%b5%d0%bb%d0%b0%d1%82%d1%8c-whatsapp-%d1%87%d0%b0%d1%82-%d0%b1%d0%be%d1%82-%d0%b8%d1%81%d0%bf%d0%be%d0%bb%d1%8c%d0%b7%d1%83%d1%8f-python-ultramsg","status":"publish","type":"post","link":"https:\/\/blog.ultramsg.com\/ru\/%d1%81%d0%b4%d0%b5%d0%bb%d0%b0%d1%82%d1%8c-whatsapp-%d1%87%d0%b0%d1%82-%d0%b1%d0%be%d1%82-%d0%b8%d1%81%d0%bf%d0%be%d0%bb%d1%8c%d0%b7%d1%83%d1%8f-python-ultramsg\/","title":{"rendered":"\u0421\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u0447\u0430\u0442-\u0431\u043e\u0442\u0430 WhatsApp \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Python"},"content":{"rendered":"\n<p><\/p>\n\n<p>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0447\u0430\u0442-\u0431\u043e\u0442\u0430 \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e \u0441 Ultramsg API, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0447\u0430\u0442-\u0431\u043e\u0442\u0430 \u0434\u043b\u044f \u043e\u0431\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 \u0438 \u043b\u0443\u0447\u0448\u0435\u0433\u043e \u0447\u0430\u0442-\u0431\u043e\u0442\u0430 \u0441 \u0438\u0441\u043a\u0443\u0441\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u0438\u043d\u0442\u0435\u043b\u043b\u0435\u043a\u0442\u043e\u043c. \u0412\u044b\u043f\u043e\u043b\u043d\u0438\u0432 \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u0448\u0430\u0433\u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u044f\u0437\u044b\u043a Python.<\/p>\n\n<h2 class=\"wp-block-heading\">\u0427\u0430\u0442-\u0431\u043e\u0442 \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0438 \u0437\u0430\u0434\u0430\u0447\u0438 \u0431\u043e\u0442\u0430 WhatsApp<\/h2>\n\n<ul class=\"wp-block-list\"><li>\u0412\u044b\u0432\u043e\u0434 \u0441\u043f\u0438\u0441\u043a\u0430 \u043a\u043e\u043c\u0430\u043d\u0434.<\/li><li>\u0412\u044b\u0432\u043e\u0434 \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0431\u043e\u0442\u0430, \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0435\u0433\u043e \u043d\u0430 .<\/li><li>\u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u043d\u0430 \u043d\u043e\u043c\u0435\u0440 \u0442\u0435\u043b\u0435\u0444\u043e\u043d\u0430 \u0438\u043b\u0438 \u0432 \u0433\u0440\u0443\u043f\u043f\u0443.<\/li><li>\u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0430\u0443\u0434\u0438\u043e\u0444\u0430\u0439\u043b\u0430.<\/li><li>\u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0430\u0443\u0434\u0438\u043e\u0437\u0430\u043f\u0438\u0441\u0438 ppt.<\/li><li>\u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0432\u0438\u0434\u0435\u043e\u0444\u0430\u0439\u043b\u0430.<\/li><li>\u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u043a\u043e\u043d\u0442\u0430\u043a\u0442\u0430.<a href=\"https:\/\/github.com\/ultramsg\/python-whatsApp-bot#getting-started\" target=\"_blank\" rel=\"noopener\"><\/a><\/li><\/ul>\n\n<h2 class=\"wp-block-heading\">\u0428\u0430\u0433 1: \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043a\u043e\u043b\u0431\u0443<br\/><\/h2>\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<pre class=\"wp-block-code\"><code><code data-enlighter-language=\"powershell\" class=\"EnlighterJSRAW\">pip install flask<\/code><\/code><\/pre>\n\n<h2 class=\"wp-block-heading\">\u0428\u0430\u0433 2: \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0435 ngrok<br\/><\/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\/\" 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<h2 class=\"wp-block-heading\">\u0428\u0430\u0433 3: \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-preformatted\"><code data-enlighter-language=\"python\" class=\"EnlighterJSRAW\">from flask import Flask, request, jsonify\nfrom ultrabot import ultraChatBot\nimport json\n\napp = Flask(__name__)\n\n@app.route('\/', methods=['POST'])\ndef home():\n    if request.method == 'POST':\n        bot = ultraChatBot(request.json)\n        return bot.Processing\u0640incoming\u0640messages()\n\nif(__name__) == '__main__':\n    app.run()<\/code><\/pre>\n\n<h2 class=\"wp-block-heading\">\u0428\u0430\u0433 4: \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>ultrabot.py<\/strong> \u0438 \u043f\u0440\u043e\u043f\u0438\u0448\u0435\u043c \u0432\u043d\u0443\u0442\u0440\u0438 \u043d\u0435\u0433\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434<\/p>\n\n<pre class=\"wp-block-preformatted\"><code data-enlighter-language=\"python\" class=\"EnlighterJSRAW\">import json\nimport requests\nimport datetime\n\nclass ultraChatBot():    \n    def __init__(self, json):\n        self.json = json\n        self.dict_messages = json['data']\n        self.ultraAPIUrl = 'https:\/\/api.ultramsg.com\/{{instance_id}}\/'\n        self.token = '{{token}}'\n\n   \n    def send_requests(self, type, data):\n        url = f\"{self.ultraAPIUrl}{type}?token={self.token}\"\n        headers = {'Content-type': 'application\/json'}\n        answer = requests.post(url, data=json.dumps(data), headers=headers)\n        return answer.json()\n\n    def send_message(self, chatID, text):\n        data = {\"to\" : chatID,\n                \"body\" : text}  \n        answer = self.send_requests('messages\/chat', data)\n        return answer\n\n    def send_image(self, chatID):\n        data = {\"to\" : chatID,\n                \"image\" : \"https:\/\/file-example.s3-accelerate.amazonaws.com\/images\/test.jpeg\"}  \n        answer = self.send_requests('messages\/image', data)\n        return answer\n\n    def send_video(self, chatID):\n        data = {\"to\" : chatID,\n                \"video\" : \"https:\/\/file-example.s3-accelerate.amazonaws.com\/video\/test.mp4\"}  \n        answer = self.send_requests('messages\/video', data)\n        return answer\n\n    def send_audio(self, chatID):\n        data = {\"to\" : chatID,\n                \"audio\" : \"https:\/\/file-example.s3-accelerate.amazonaws.com\/audio\/2.mp3\"}  \n        answer = self.send_requests('messages\/audio', data)\n        return answer\n\n\n    def send_voice(self, chatID):\n        data = {\"to\" : chatID,\n                \"audio\" : \"https:\/\/file-example.s3-accelerate.amazonaws.com\/voice\/oog_example.ogg\"}  \n        answer = self.send_requests('messages\/voice', data)\n        return answer\n\n    def send_contact(self, chatID):\n        data = {\"to\" : chatID,\n                \"contact\" : \"14000000001@c.us\"}  \n        answer = self.send_requests('messages\/contact', data)\n        return answer\n\n\n    def time(self, chatID):\n        t = datetime.datetime.now()\n        time = t.strftime('%Y-%m-%d %H:%M:%S')\n        return self.send_message(chatID, time)\n\n\n    def welcome(self,chatID, noWelcome = False):\n        welcome_string = ''\n        if (noWelcome == False):\n            welcome_string = \"Hi , welcome to WhatsApp chatbot using Python\\n\"\n        else:\n            welcome_string = \"\"\"wrong command\nPlease type one of these commands:\n*hi* : Saluting\n*time* : show server time\n*image* : I will send you a picture\n*video* : I will send you a Video\n*audio* : I will send you a audio file\n*voice* : I will send you a ppt audio recording\n*contact* : I will send you a contact\n\"\"\"\n        return self.send_message(chatID, welcome_string)\n\n\n    def Processing\u0640incoming\u0640messages(self):\n        if self.dict_messages != []:\n            message =self.dict_messages\n            text = message['body'].split()\n            if not message['fromMe']:\n                chatID  = message['from'] \n                if text[0].lower() == 'hi':\n                    return self.welcome(chatID)\n                elif text[0].lower() == 'time':\n                    return self.time(chatID)\n                elif text[0].lower() == 'image':\n                    return self.send_image(chatID)\n                elif text[0].lower() == 'video':\n                    return self.send_video(chatID)\n                elif text[0].lower() == 'audio':\n                    return self.send_audio(chatID)\n                elif text[0].lower() == 'voice':\n                    return self.send_voice(chatID)\n                elif text[0].lower() == 'contact':\n                    return self.send_contact(chatID)\n                else:\n                    return self.welcome(chatID, True)\n            else: return 'NoCommand'<\/code><\/pre>\n\n<h2 class=\"wp-block-heading\">\u0428\u0430\u0433 5: \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 \u043f\u0440\u043e\u0435\u043a\u0442 WhatsApp Chatbot <\/h2>\n\n<h3 class=\"wp-block-heading\">\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c FLASK-\u0441\u0435\u0440\u0432\u0435\u0440<\/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\">\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043d\u0433\u0440\u043e\u043a<\/h3>\n\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 ngrok \u0434\u043b\u044f Windows:<\/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>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 ngrok \u0434\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<h2 class=\"wp-block-heading\">\u0428\u0430\u0433 6. \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0435 \u0432\u0435\u0431-\u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u0447\u0438\u043a URL \u0432 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430\u0445 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430.<\/h2>\n\n<p>\u041f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 ngrok \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\"><img decoding=\"async\" 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\" title=\"\"><\/figure><\/div>\n\n<h2 class=\"wp-block-heading\">\u0424\u0443\u043d\u043a\u0446\u0438\u0438 \u0447\u0430\u0442-\u0431\u043e\u0442\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0432 \u043a\u043e\u0434\u0435<\/h2>\n\n<h3 class=\"wp-block-heading\">send_message<\/h3>\n\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 WhatsApp<\/p>\n\n<pre class=\"wp-block-code\"><code><code data-enlighter-language=\"python\" class=\"EnlighterJSRAW\">def send_message(self, chatID, text):\n    data = {\"to\" : chatID,\n        \"body\" : text}  \n    answer = self.send_requests('messages\/chat', data)\n    return answer<\/code><\/code><\/pre>\n\n<ul class=\"wp-block-list\"><li>ChatID \u2013 ID \u0447\u0430\u0442\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0435\u043c\u0443 \u043d\u0443\u0436\u043d\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 <a href=\"mailto:14155552671@c.us\">14155552671@c.us<\/a> .<\/li><li>\u0422\u0435\u043a\u0441\u0442 \u2013 \u0442\u0435\u043a\u0441\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f.<\/li><\/ul>\n\n<h3 class=\"wp-block-heading\">time<\/h3>\n\n<p>\u041e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u0441\u0435\u0440\u0432\u0435\u0440\u0430.<\/p>\n\n<pre class=\"wp-block-code\"><code><code data-enlighter-language=\"python\" class=\"EnlighterJSRAW\">def time(self, chatID):\n    t = datetime.datetime.now()\n    time = t.strftime('%Y-%m-%d %H:%M:%S')\n    return self.send_message(chatID, time)<\/code><\/code><\/pre>\n\n<ul class=\"wp-block-list\"><li>ChatID \u2013 ID \u0447\u0430\u0442\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0435\u043c\u0443 \u043d\u0443\u0436\u043d\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 <a href=\"mailto:14155552671@c.us\">14155552671@c.us<\/a> .<\/li><\/ul>\n\n<h3 class=\"wp-block-heading\">send_image<\/h3>\n\n<p>\u041e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043d\u0430 \u043d\u043e\u043c\u0435\u0440 \u0442\u0435\u043b\u0435\u0444\u043e\u043d\u0430 \u0438\u043b\u0438 \u0432 \u0433\u0440\u0443\u043f\u043f\u0443<\/p>\n\n<pre class=\"wp-block-code\"><code><code data-enlighter-language=\"python\" class=\"EnlighterJSRAW\">def send_image(self, chatID):\n    data = {\"to\" : chatID,\n        \"image\" : \"https:\/\/file-example.s3-accelerate.amazonaws.com\/images\/test.jpeg\"}  \n    answer = self.send_requests('messages\/image', data)\n    return answer<\/code><\/code><\/pre>\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/github.com\/ultramsg\/python-whatsApp-bot#send_video\" target=\"_blank\" rel=\"noopener\"><\/a><a href=\"https:\/\/github.com\/ultramsg\/python-whatsApp-bot#send_image\" target=\"_blank\" rel=\"noopener\"><\/a><\/h2>\n\n<h3 class=\"wp-block-heading\">send_video<\/h3>\n\n<p>\u041e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0432\u0438\u0434\u0435\u043e \u043d\u0430 \u043d\u043e\u043c\u0435\u0440 \u0442\u0435\u043b\u0435\u0444\u043e\u043d\u0430 \u0438\u043b\u0438 \u0432 \u0433\u0440\u0443\u043f\u043f\u0443<\/p>\n\n<pre class=\"wp-block-code\"><code><code data-enlighter-language=\"python\" class=\"EnlighterJSRAW\">def send_video(self, chatID):\n    data = {\"to\" : chatID,\n        \"video\" : \"https:\/\/file-example.s3-accelerate.amazonaws.com\/video\/test.mp4\"}  \n    answer = self.send_requests('messages\/video', data)\n    return answer<\/code><\/code><\/pre>\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/github.com\/ultramsg\/python-whatsApp-bot#time\" target=\"_blank\" rel=\"noopener\"><\/a><\/h2>\n\n<h3 class=\"wp-block-heading\">send_audio<\/h3>\n\n<p>\u041e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0430\u0443\u0434\u0438\u043e\u0444\u0430\u0439\u043b \u043d\u0430 \u043d\u043e\u043c\u0435\u0440 \u0442\u0435\u043b\u0435\u0444\u043e\u043d\u0430 \u0438\u043b\u0438 \u0433\u0440\u0443\u043f\u043f\u0443<\/p>\n\n<pre class=\"wp-block-code\"><code><code data-enlighter-language=\"python\" class=\"EnlighterJSRAW\">def send_audio(self, chatID):\n    data = {\"to\" : chatID,\n        \"audio\" : \"https:\/\/file-example.s3-accelerate.amazonaws.com\/audio\/2.mp3\"}  \n    answer = self.send_requests('messages\/audio', data)\n    return answer<\/code><\/code><\/pre>\n\n<h3 class=\"wp-block-heading\">send_voice<br\/><\/h3>\n\n<p>\u041e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0430\u0443\u0434\u0438\u043e\u0437\u0430\u043f\u0438\u0441\u044c ppt \u043d\u0430 \u043d\u043e\u043c\u0435\u0440 \u0442\u0435\u043b\u0435\u0444\u043e\u043d\u0430 \u0438\u043b\u0438 \u0433\u0440\u0443\u043f\u043f\u0443<\/p>\n\n<pre class=\"wp-block-code\"><code><code data-enlighter-language=\"python\" class=\"EnlighterJSRAW\">def send_voice(self, chatID):\n    data = {\"to\" : chatID,\n        \"audio\" : \"https:\/\/file-example.s3-accelerate.amazonaws.com\/voice\/oog_example.ogg\"}  \n    answer = self.send_requests('messages\/voice', data)\n    return answer<\/code><\/code><\/pre>\n\n<h3 class=\"wp-block-heading\">send_contact<\/h3>\n\n<p>\u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0430\u043a\u0442\u0430 \u0438\u043b\u0438 \u0441\u043f\u0438\u0441\u043a\u0430 \u043a\u043e\u043d\u0442\u0430\u043a\u0442\u043e\u0432 \u043d\u0430 \u043d\u043e\u043c\u0435\u0440 \u0442\u0435\u043b\u0435\u0444\u043e\u043d\u0430 \u0438\u043b\u0438 \u0433\u0440\u0443\u043f\u043f\u0443<\/p>\n\n<pre class=\"wp-block-code\"><code><code data-enlighter-language=\"python\" class=\"EnlighterJSRAW\">def send_contact(self, chatID):\n    data = {\"to\" : chatID,\n        \"contact\" : \"14000000001@c.us\"}  \n    answer = self.send_requests('messages\/contact', data)\n    return answer<\/code><\/code><\/pre>\n\n<h3 class=\"wp-block-heading\">Processing\u0640incoming\u0640messages<\/h3>\n\n<pre class=\"wp-block-code\"><code><code data-enlighter-language=\"python\" class=\"EnlighterJSRAW\">def Processing\u0640incoming\u0640messages(self):\n    if self.dict_messages != &#91;]:\n        message =self.dict_messages\n        text = message&#91;'body'].split()\n        if not message&#91;'fromMe']:\n        chatID  = message&#91;'from'] \n        if text&#91;0].lower() == 'hi':\n            return self.welcome(chatID)\n        elif text&#91;0].lower() == 'time':\n            return self.time(chatID)\n        elif text&#91;0].lower() == 'image':\n            return self.send_image(chatID)\n        elif text&#91;0].lower() == 'video':\n            return self.send_video(chatID)\n        elif text&#91;0].lower() == 'audio':\n            return self.send_audio(chatID)\n        elif text&#91;0].lower() == 'voice':\n            return self.send_voice(chatID)\n        elif text&#91;0].lower() == 'contact':\n            return self.send_contact(chatID)\n        else:\n            return self.welcome(chatID, True)\n        else: return 'NoCommand'<\/code><\/code><\/pre>\n\n<p>\u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0435 \u0448\u0430\u0433\u0438 \u0432 \u044d\u0442\u043e\u043c \u0432\u0438\u0434\u0435\u043e:<\/p>\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=\"Build a WhatsApp Chatbot With Python using Ultramsg WhatsApp API\" width=\"1200\" height=\"675\" src=\"https:\/\/www.youtube.com\/embed\/W3dQp375wWY?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\">\u041f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u0441\u0441\u044b\u043b\u043a\u0438<\/h2>\n\n<ul class=\"wp-block-list\"><li>\u0412\u0435\u0441\u044c \u043a\u043e\u0434 \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u043d\u0430 <a href=\"https:\/\/github.com\/ultramsg\/python-whatsApp-bot\" target=\"_blank\" rel=\"noopener\">GitHub<\/a> .<\/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%bf%d1%80%d0%be%d0%b3%d1%80%d0%b0%d0%bc%d0%bc%d0%b8%d1%80%d1%83%d0%b5%d0%bc%d1%8b%d0%b9-whatsapp-api-%d0%be%d0%b1%d0%bc%d0%b5%d0%bd-%d1%81%d0%be%d0%be%d0%b1%d1%89%d0%b5%d0%bd%d0%b8%d1%8f%d0%bc\/\" data-type=\"URL\" data-id=\"https:\/\/blog.ultramsg.com\/programmable-whatsapp-api-messaging-using-python\/\">API WhatsApp<\/a> \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Python.<\/li><li><a href=\"https:\/\/www.youtube.com\/watch?v=kipBHDOsFKI\" data-type=\"URL\" data-id=\"https:\/\/www.youtube.com\/watch?v=kipBHDOsFKI\" rel=\"nofollow noopener\" target=\"_blank\">\u043a\u0430\u043a \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c WebHooks \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b Ultramsg<\/a><\/li><li>\u041a\u0430\u043a <a 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\/\" data-type=\"URL\" data-id=\"https:\/\/blog.ultramsg.com\/how-to-receive-whatsapp-messages-python-webhook\/\">\u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f WhatsApp<\/a> \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e python \u0438 webhook.<\/li><\/ul>\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0447\u0430\u0442-\u0431\u043e\u0442\u0430 \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e \u0441 Ultramsg API, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0447\u0430\u0442-\u0431\u043e\u0442\u0430 \u0434\u043b\u044f \u043e\u0431\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 \u0438 &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"\u0421\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u0447\u0430\u0442-\u0431\u043e\u0442\u0430 WhatsApp \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Python\" class=\"read-more button\" href=\"https:\/\/blog.ultramsg.com\/ru\/%d1%81%d0%b4%d0%b5%d0%bb%d0%b0%d1%82%d1%8c-whatsapp-%d1%87%d0%b0%d1%82-%d0%b1%d0%be%d1%82-%d0%b8%d1%81%d0%bf%d0%be%d0%bb%d1%8c%d0%b7%d1%83%d1%8f-python-ultramsg\/#more-1907\" aria-label=\"\u041f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u043e \u0421\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u0447\u0430\u0442-\u0431\u043e\u0442\u0430 WhatsApp \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Python\">Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":1849,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[132],"tags":[134,150,136,178],"class_list":["post-1907","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-api-whatsapp-ru","tag-api-whatsapp-ru","tag-150","tag-136","tag-178","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\/1907","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=1907"}],"version-history":[{"count":6,"href":"https:\/\/blog.ultramsg.com\/ru\/wp-json\/wp\/v2\/posts\/1907\/revisions"}],"predecessor-version":[{"id":1931,"href":"https:\/\/blog.ultramsg.com\/ru\/wp-json\/wp\/v2\/posts\/1907\/revisions\/1931"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ultramsg.com\/ru\/wp-json\/wp\/v2\/media\/1849"}],"wp:attachment":[{"href":"https:\/\/blog.ultramsg.com\/ru\/wp-json\/wp\/v2\/media?parent=1907"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ultramsg.com\/ru\/wp-json\/wp\/v2\/categories?post=1907"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ultramsg.com\/ru\/wp-json\/wp\/v2\/tags?post=1907"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}