Make WhatsApp ChatBot and use WhatsApp API to send the WhatsApp messages in python .

Overview

Ultramsg.com WhatsApp Bot using WhatsApp API and ultramsg

Demo WhatsApp API ChatBot using Ultramsg API with python.

Opportunities and tasks:

  • The output of the command list .
  • The output of the server time of the bot running on .
  • Sending image to phone number or group .
  • Sending audio file .
  • Sending ppt audio recording .
  • Sending Video File.
  • Sending contact .

Getting Started

  • Ultramsg account is required to run examples. Log in or Create Account if you don't have one ultramsg.com.
  • go to your instance or Create one if you haven't already.
  • Scan Qr and make sure that instance Auth Status : authenticated

install flask

the 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.

pip install flask

Then clone the repository for yourself. Then go to the ultrabot.py file and replace the ultraAPIUrl and instance token.

install ngrok

for local development purposes, a tunneling service is required. This example uses ngrok , You can download ngrok from here : ngrok .

Class 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 .

Run a chatbot

Run FLASK server

flask run

Run ngrok

Run ngrok For Windows :

ngrok http 5000

Run ngrok For Mac :

./ngrok http 5000

Functions

send_request

Used to send requests to the Ultramsg API

def send_requests(self, type, data):
    url = f"{self.ultraAPIUrl}{type}?token={self.token}"
    headers = {'Content-type': 'application/json'}
    answer = requests.post(url, data=json.dumps(data), headers=headers)
    return answer.json()
  • type determines the type message .
  • data contains the data required for sending requests.

send_message

Used to send WhatsApp text messages

def send_message(self, chatID, text):
    data = {"to" : chatID,
        "body" : text}  
    answer = self.send_requests('messages/chat', data)
    return answer

time

Sends the current server time .

def time(self, chatID):
    t = datetime.datetime.now()
    time = t.strftime('%d:%m:%Y')
    return self.send_message(chatID, time)
  • ChatID – ID of the chat where the message should be sent for him, e.g [email protected] .

send_image

Send a image to phone number or group

def send_image(self, chatID):
    data = {"to" : chatID,
        "image" : "https://file-example.s3-accelerate.amazonaws.com/images/test.jpeg"}  
    answer = self.send_requests('messages/image', data)
    return answer
  • ChatID – ID of the chat where the message should be sent for him, e.g [email protected] .

send_video

Send a Video to phone number or group

def send_video(self, chatID):
    data = {"to" : chatID,
        "video" : "https://file-example.s3-accelerate.amazonaws.com/video/test.mp4"}  
    answer = self.send_requests('messages/video', data)
    return answer
  • ChatID – ID of the chat where the message should be sent for him, e.g [email protected] .

send_audio

Send a audio file to phone number or group

def send_audio(self, chatID):
    data = {"to" : chatID,
        "audio" : "https://file-example.s3-accelerate.amazonaws.com/audio/2.mp3"}  
    answer = self.send_requests('messages/audio', data)
    return answer
  • ChatID – ID of the chat where the message should be sent for him, e.g [email protected] .

send_voice

Send a ppt audio recording to phone number or group

def send_voice(self, chatID):
    data = {"to" : chatID,
        "audio" : "https://file-example.s3-accelerate.amazonaws.com/voice/oog_example.ogg"}  
    answer = self.send_requests('messages/voice', data)
    return answer
  • ChatID – ID of the chat where the message should be sent for him, e.g [email protected] .

send_contact

Sending one contact or contact list to phone number or group

def send_contact(self, chatID):
    data = {"to" : chatID,
        "contact" : "[email protected]"}  
    answer = self.send_requests('messages/contact', data)
    return answer
  • ChatID – ID of the chat where the message should be sent for him, e.g [email protected] .

Incoming message processing

def Processingـincomingـmessages(self):
    if self.dict_messages != []:
        message =self.dict_messages
        text = message['body'].split()
        if not message['fromMe']:
        chatID  = message['from'] 
        if text[0].lower() == 'hi':
            return self.welcome(chatID)
        elif text[0].lower() == 'time':
            return self.time(chatID)
        elif text[0].lower() == 'image':
            return self.send_image(chatID)
        elif text[0].lower() == 'video':
            return self.send_video(chatID)
        elif text[0].lower() == 'audio':
            return self.send_audio(chatID)
        elif text[0].lower() == 'voice':
            return self.send_voice(chatID)
        elif text[0].lower() == 'contact':
            return self.send_contact(chatID)
        else:
            return self.welcome(chatID, True)
        else: return 'NoCommand'

Flask

To process incoming messages to our server

from flask import Flask, request, jsonify
from ultrabot import ultraChatBot
import json

app = Flask(__name__)

@app.route('/', methods=['POST'])
def home():
    if request.method == 'POST':
    bot = ultraChatBot(request.json)
    return bot.Processingـincomingـmessages()

if(__name__) == '__main__':
    app.run()

We 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 .

You might also like...
Send SMS text messages via email with as many accounts as you want :)
Send SMS text messages via email with as many accounts as you want :)

SMS-Spammer Send SMS text messages via email with as many accounts as you want :) Example Set Up Guide! To start log into the gmail account you would

NoChannelBot - Bot bans users, that send messages like channels

No Channel Bot Say "STOP" to users who send messages as channels! Bot prevents u

A python tool to Automate Whatsapp through Whatsapp web

This python tool is used to Automate Whatsapp through Whatsapp web. We can add number of contacts whom we want to send text messages on perticular time

Simple software that can send WhatsApp message to a single or multiple users (including unsaved number**)

wp-automation Info: this is a simple automation software that sends WhatsApp message to single or multiple users. Key feature: -Sends message to multi

Send automated wishes to your contacts at scheduled time through WhatsApp. Written for Raspberry pi.

Whatsapp Automated Wishes Helps to send automated wishes to your contacts in Whatsapp at scheduled time using pywhatkit . Written for Raspberry pi. Wi

Automatically send commands to send Twitch followers to any Twitch account.
Automatically send commands to send Twitch followers to any Twitch account.

Automatically send commands to send Twitch followers to any Twitch account. You just need to be in a Twitch follow bot Discord server!

Sends messages to a Discord webhook whenever you make a new commit to your local git repository.
Sends messages to a Discord webhook whenever you make a new commit to your local git repository.

Git-Notif Sends messages to a Discord webhook whenever you make a new commit to your local git repository. Usage Just drop notifier.py into your git h

A python to scratch API connector. Can fetch data from the API and send it back in cloud variables.

Scratch2py Scratch2py or S2py is a easy to use, versatile tool to communicate with the Scratch API Based of scratchclient by Raihan142857 Installation

Telegram PHub Bot using ARQ Api and Pyrogram. This Bot can Download and Send PHub HQ videos in Telegram using ARQ API.

Tg_PHub_Bot Telegram PHub Bot using ARQ Api and Pyrogram. This Bot can Download and Send PHub HQ videos in Telegram using ARQ API. OS Support All linu

Releases(v1.0.0)
Owner
Ultramsg
WhatsApp API gateway for chatbot and sending messages, media, marketing campaigns for PHP, nodejs , JavaScript, and Python
Ultramsg
Let your friends know when you are online and offline xD

Twitter Last Seen Activity Let your friends know when you are online and offline Laser-light eyes when online Last seen is mentioned in user bio Also

Kush Choudhary 12 Aug 16, 2021
A python script that can send notifications to your phone via SMS text

Discord SMS Notification A python script that help you send text message to your phone one of your desire discord channel have a new message. The proj

2 Apr 25, 2022
An accessible Archive of Our Own reader application written in python.

AO3-A11y. Important disclaimer. This project is under active development. Many features might not yet be present, or some things might not work at all

4 Nov 11, 2022
A qq bot based on nonebot2 and go-cqhttp

Asoul-bot A qq bot based on nonebot and go-cqhttp 你可以将bot部署在本地,也可以加入bot测试群:784280070(全体禁言) 你可以通过临时会话的方式向bot发送指令,输入help获取帮助菜单 本地部署请参考:https://zhuanlan.

11 Sep 23, 2022
Python wrapper for CoWin API's

Cowin Tracker Python API wrapper for CoWin, India's digital platform launched by the government to help citizens register themselves for the vaccinati

Saiprasad Balasubramanian 43 Jun 11, 2022
This bot is created by AJTimePyro and It accepts direct downloading url & then return file as telegram file.

URL Uploader Bot This is the source code of URL Uploader Bot. And the developer of this bot is AJTimePyro, His Telegram Channel & Group. You can use t

Abhijeet 23 Nov 13, 2022
A (probably) working Kik name checker

KikNameChecker !THIS ONLY CHECKS WS2.KIK.COM ENDPOINT! \ Will add user inputted endpoints thing \ A (probably) working Kik name checker Started as a s

insert edgy and cool name 1 Dec 17, 2022
Home Assistant for Opendata CWB. Get the weather forecast of the city in Taiwan.

Home assistant support for Opendata CWB. The readme in Traditional Chinese. This integration is based on OpenWeatherMap (@csparpa, pyowm) to develop.

11 Sep 30, 2022
Instagram GiftShop Scam Killer

Instagram GiftShop Scam Killer A basic tool for Windows which kills acess to any giftshop scam from Instagram. Protect your Instagram account from the

1 Mar 31, 2022
Netflix Movies and TV Series Downloader Tool including CDM L1 which you guys can Donwload 4K Movies

NFRipper2.0 I could not shared all the code here Because its has lots of files inisde it https://new.gdtot.me/file/86651844 - Downoad File From Here.

Kiran 15 May 06, 2022
Palo Alto Networks PAN-OS SDK for Python

Palo Alto Networks PAN-OS SDK for Python The PAN-OS SDK for Python (pan-os-python) is a package to help interact with Palo Alto Networks devices (incl

Palo Alto Networks 281 Dec 09, 2022
A simple discord bot named atticus that sends you the timetable of your classes upon request

A simple discord bot named atticus that sends you the timetable of your classes upon request. Soon, it would you ping you before classes too!

Samhitha 3 Oct 13, 2022
Pythonic wrapper for the Aladhan prayer times API.

aladhan.py is a pythonic wrapper for the Aladhan prayer times API. Installation Python 3.6 or higher is required. To Install aladhan.py with pip: pip

HETHAT 8 Aug 17, 2022
Discord-Wrapper - Discord Websocket Wrapper in python

This does not currently work and is in development Discord Websocket Wrapper in

3 Oct 25, 2022
OpenQuake's Engine for Seismic Hazard and Risk Analysis

OpenQuake Engine The OpenQuake Engine is an open source application that allows users to compute seismic hazard and seismic risk of earthquakes on a g

Global Earthquake Model 281 Dec 21, 2022
A simple telegram bot to help you to remove forward tag from post from any messages . Maded in python3 using @Pyrogram . Developed by @Kunal-Diwan

Frwd-Tag-Remover Telegram Bot to Remove forward tag from any Post . If you need any more modes in repo or If you find out any bugs, mention in @Develo

Kunal Diwan 2 Oct 14, 2022
The WhatsApp lib

yowsup WARNING It seems that recently yowsup gets detected during registration resulting in an instant ban for your number right after registering wit

Tarek 6.8k Jan 04, 2023
Telegram Bot for generating and decoding QR-codes

Telegram openqrgen_bot Telegram Bot that generates from user's messages and decodes QR-codes from photos. Also contains rickroll detection :) Just typ

2 Nov 14, 2021
Wats2PDF - Convert whatsapp exported chat(without media) into a readable pdf format

Wats2PDF convert whatsApp exported chat into a readable pdf format. convert with

5 Apr 26, 2022
Bootstrapping your personal Web3 info hub from more than 500 RSS Feeds.

RSS Aggregator for Web3 (or 🥩 RAW for short) Bootstrapping your personal Web3 info hub from more than 500 RSS Feeds. What is RSS or Reader Services?

ChainFeeds 1.8k Dec 29, 2022