Python Automation

How to create a WhatsApp bot in Python with BotCity

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:

python


from botcity.plugins.whatsapp import BotWhatsappPlugin

token = "<YOUR_ACCESS_TOKEN>"

number_id = "<YOUR_WHATSAPP_NUMBER_ID>"

whatsapp = BotWhatsappPlugin(access_token=token, whatsapp_number_id=number_id)

whatsapp.send_text_message("5519987654321", "This is a simple test message! 😃")

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:

pip install --upgrade -r requirements.txt

Once installed, test the bot by running:

python bot.py

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

Why create a WhatsApp bot with Python?

Automating messages on WhatsApp can bring several benefits, such as:

  • Faster customer service: quick replies without relying on a 24/7 team;

  • Cost reduction: saving time and operational resources;

  • Greater scalability: ability to interact with multiple contacts simultaneously.

Why use BotCity to create your bot?

BotCity stands out for offering a complete and robust platform for intelligent automation. Key advantages include:

  • Scalable execution and orchestration with the Orchestrator;

  • Low operational cost by eliminating the need for paid external APIs;

  • Greater control over automation and custom integrations.

Use cases for WhatsApp bots

Check out the main scenarios where a WhatsApp bot can be useful for your business:

Automated customer service

A company can create a bot to automatically answer frequently asked questions, reducing the support team’s workload and improving customer experience.

Notifications and reminders

Businesses can use bots to send appointment confirmations, order status updates, or payment reminders automatically.

Feedback collection

Companies can create bots to send satisfaction surveys and collect real-time responses from customers, helping improve their services.

Ready to set up your WhatsApp bot?

Creating a WhatsApp bot in Python with BotCity is an efficient solution to automate interactions, boost productivity, and cut costs. This way, you can build an intelligent and highly scalable automation flow.

If you’re ready to take your company’s automation to the next level, explore BotCity’s solutions and get started today!

Leave a Reply

Discover more from Blog BotCity - Content for Automation and Governance

Subscribe now to keep reading and get access to the full archive.

Continue reading