Automating WhatsApp messaging has become essential for businesses looking to improve customer communication and optimize processes. With BotCity, you can create a WhatsApp bot using Python, without relying on unofficial APIs.
In this article, we’ll walk you through the step-by-step process of creating your WhatsApp bot with BotCity, exploring its advantages, use cases, and best practices to ensure secure and efficient automation. Keep reading!
Step-by-step to create a WhatsApp bot in Python
1. Create a project
To start the project, let’s create two main files: the dependency list file named requirements.txt and the bot code file bot.py.
In the dependencies file, add the BotCity plugin that simplifies sending WhatsApp messages:
botcity-whatsapp-plugin
In the Python file, where you’ll configure and define the bot’s actions, start with a simple code snippet like this:
To use the plugin, you’ll need an access token and a WhatsApp number ID — both generated directly in Meta’s developer portal.
If you don’t have those yet, follow Meta’s account setup tutorial and generate the required token and number ID.
Once you have them, replace the values in the token and number_id variables in the code.
Learn more: List of essential Python libraries
2. Local installation and testing
With the basic code ready, you can now install the dependencies and run a local test.
In the terminal, make sure you’re in the project folder and run:
You should see the message successfully sent in the WhatsApp app.
3. Orchestrate the bot
With the code tested and running, you can scale execution or automate interactions with multiple contacts using BotCity Orchestrator, ensuring continuous operation and remote monitoring.
Learn more: What is orchestration in IT?
Create a .zip package of your project and in 3 simple steps, deploy it to the platform.
Learn more: Easy Deploy
Use features like parameters to send messages to different phone numbers.
Learn more: Parameters
Keep your sensitive data secure by storing tokens and identifiers as credentials.
Learn more: Credentials
Also, explore other message types, like media messages.
Learn more: How to send media messages