{"id":19900428,"url":"https://github.com/ultramsg/python-whatsapp-bot","last_synced_at":"2026-03-15T05:11:43.256Z","repository":{"id":49169388,"uuid":"469079853","full_name":"ultramsg/python-whatsApp-bot","owner":"ultramsg","description":"Make WhatsApp ChatBot and use WhatsApp API to send the WhatsApp messages in python . ","archived":false,"fork":false,"pushed_at":"2023-01-11T08:38:14.000Z","size":34,"stargazers_count":117,"open_issues_count":0,"forks_count":86,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-07T08:17:37.714Z","etag":null,"topics":["bot","chatbot","python","whatsapp-api","whatsapp-api-python","whatsapp-bot"],"latest_commit_sha":null,"homepage":"https://ultramsg.com","language":"Python","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/ultramsg.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}},"created_at":"2022-03-12T12:44:14.000Z","updated_at":"2025-03-15T04:40:54.000Z","dependencies_parsed_at":"2023-02-09T02:15:18.535Z","dependency_job_id":null,"html_url":"https://github.com/ultramsg/python-whatsApp-bot","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ultramsg%2Fpython-whatsApp-bot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ultramsg%2Fpython-whatsApp-bot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ultramsg%2Fpython-whatsApp-bot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ultramsg%2Fpython-whatsApp-bot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ultramsg","download_url":"https://codeload.github.com/ultramsg/python-whatsApp-bot/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252122147,"owners_count":21698304,"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":["bot","chatbot","python","whatsapp-api","whatsapp-api-python","whatsapp-bot"],"created_at":"2024-11-12T20:12:20.771Z","updated_at":"2026-03-15T05:11:38.212Z","avatar_url":"https://github.com/ultramsg.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [Ultramsg.com](https://ultramsg.com/?utm_source=github\u0026utm_medium=python\u0026utm_campaign=chatbot) WhatsApp Bot using WhatsApp API and ultramsg\nDemo WhatsApp API ChatBot using [Ultramsg API](https://ultramsg.com/?utm_source=github\u0026utm_medium=python\u0026utm_campaign=chatbot) with python.\n# Opportunities and tasks:\n- The output of the command list .\n- The output of the server time of the bot running on .\n- Sending image to phone number or group .\n- Sending audio file .\n- Sending ppt audio recording .\n- Sending Video File.\n- Sending contact .\n\n# Getting Started\n- Ultramsg account is required to run examples. Log in or Create Account if you don't have one [ultramsg.com](https://ultramsg.com/?utm_source=github\u0026utm_medium=python\u0026utm_campaign=chatbot).\n- go to your instance or Create one if you haven't already.\n- Scan Qr and make sure that instance Auth Status : authenticated\n\n## install flask\nthe WebHook URL must be provided for the server to trigger our script for incoming messages. we will deployed the server using the FLASK microframework. The FLASK server allows us to conveniently process incoming requests.\n\n\u003e pip install flask\n\nThen clone the repository for yourself.\nThen go to the **ultrabot.py** file and replace the ultraAPIUrl and instance token.\n\n## install ngrok\nfor local development purposes, a tunneling service is required. This example uses ngrok , You can download ngrok from here : [ngrok](https://ngrok.com/download) .\n\n\nClass constructor, the default one that will accept JSON, which will contain information about incoming messages (it will be received by WebHook and forwarded to the class). To see how the received JSON will look this [video](https://www.youtube.com/watch?v=kipBHDOsFKI) .\n\n\n# Run a chatbot\n\n## Run FLASK server  \n\u003e flask run\n\n## Run ngrok\n\n### Run ngrok For Windows :\n\u003e ngrok http 5000\n\n### Run ngrok For Mac :\n\u003e ./ngrok http 5000\n\n# Functions\n## send_request \nUsed to send requests to the Ultramsg API\n```python\ndef 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- **type** determines the type message .\n- **data** contains the data required for sending requests.\n\n## send_message\nUsed to send WhatsApp text messages\n```python\ndef 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- ChatID – ID of the chat where the message should be sent for him, e.g 14155552671@c.us . \n- Text – Text of the message .\n\n\n## time\nSends the current server time .\n```python\ndef time(self, chatID):\n    t = datetime.datetime.now()\n    time = t.strftime('%d:%m:%Y')\n    return self.send_message(chatID, time)\n```\n- ChatID – ID of the chat where the message should be sent for him, e.g 14155552671@c.us .\n\n## send_image\nSend a image to phone number or group\n```python\ndef 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- ChatID – ID of the chat where the message should be sent for him, e.g 14155552671@c.us .\n\n## send_video\nSend a Video to phone number or group\n```python\ndef 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- ChatID – ID of the chat where the message should be sent for him, e.g 14155552671@c.us .\n\n## send_audio\nSend a audio file to phone number or group\n```python\ndef 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- ChatID – ID of the chat where the message should be sent for him, e.g 14155552671@c.us .\n\n\n## send_voice\nSend a ppt audio recording to phone number or group\n```python\ndef 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- ChatID – ID of the chat where the message should be sent for him, e.g 14155552671@c.us .\n\n## send_contact\nSending one contact or contact list to phone number or group\n```python\ndef 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- ChatID – ID of the chat where the message should be sent for him, e.g 14155552671@c.us .\n\n# Incoming message processing\n```python\ndef Processingـincomingـmessages(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'\n```\n\n# Flask \nTo process incoming messages to our server \n\n```python\nfrom 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ـincomingـmessages()\n\nif(__name__) == '__main__':\n    app.run()\n\n```\n\nWe will write the path app.route('/', methods = ['POST']) for it. This decorator means that our home function will be called every time our FLASK server .\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fultramsg%2Fpython-whatsapp-bot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fultramsg%2Fpython-whatsapp-bot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fultramsg%2Fpython-whatsapp-bot/lists"}