Automate your Whatsapp Business with Streamlit without Twilio [Web App]
In the quest to automate every tedious task that a business does every day, I came up with a use case that would any business to automate sending a text to their new customers, here the tedious task being saving the customer contacted and pasting the same message all over again, it is not that of a tedious task if the number of people to text to is less, yet if its a large number it is indeed quite tedious.
There are quite a lot of libraries that help in the automation of WhatsApp messages. For instance, with the help of the selenium chrome web driver, we can send texts to people, yet it does require a bit of coding knowledge to actually run it, but here with the power of streamlit for the user input, and pywhatkit for sending texts, which upon deployment, can actually be given to any person for automating the text.
here, we take input from the user for the phone number and text message, that is to be sent. Users can input any number of phone numbers each separated by comma (,) that they want to send the same message, and just click enter and the app would automatically open WhatsApp web and send the phone numbers the message (User will have login their phone via QR code on web.whatsapp.com beforehand).
import streamlit as stimport datetimeimport pywhatkit as py
Import relevant libraries ie streamlit for user input on the front end, datetime to get the current time, and pywhatkit for automation.
phonelist = st.text_input("Please input numbers you want to automate with seperated by ,")message = st.text_area("Enter your Message")submit = st.button("Enter")
Placeholders at the front end to gather the user input
i=1if submit:phone = phonelist.split(',')for each in phone:py.sendwhatmsg("+968"+each,message,time.hour,(time.minute+i),10)i=i+1st.success("Message Sent!")
Upon clicking the submit button, our phone numbers list would loop through each number and send the message. here I am using +968 as country code, we could replace it with any country code you wish. The function pywhatkit.sendwhatmsg takes input phone number, message, time of an hour, and time of minute in 24-hour format to send the message. Since we are in the loop I am adding one minute of extra time (ie i=i+1) to avoid the WhatsApp ban. Upon delivery of all messages, you will receive a message from streamlit success component stating “message sent”.
Connect with me on LinkedIn for more automation fun.
“Automation applied to an inefficient operation will magnify the inefficiency.” — Bill Gates.