Help Desk
  • Getting Started
    • 🙌Welcome to Whapi.Cloud
    • 💰Pricing
    • ☕Partners
    • 🚀Getting started
    • 👨‍💻API Docs
      • Developer hubs
      • Swagger environment
      • Postman collection
  • Sending
    • Introduction
    • Send text message
      • Whatsapp API send message PHP
      • Whatsapp API send message Python
      • Whatsapp API send message Node JS
      • Whatsapp API send message С#
      • Whatsapp API send message Java
      • API integration with VB6
      • Whatsapp API send message GO (Golang)
    • Send video, audio, image, document
    • Send Group message
    • Send post to WhatsApp Channel
    • Send message with Buttons
    • Send Emoji
    • Overview of other methods for sending
      • Send Voice message
      • Send contact (vCard)
      • Send message reactions
  • Receiving
    • Introduction
    • Webhooks
      • Our webhooks (Tracked events)
      • Where to Find the Webhook URL?
      • Set the webhook link to the channel
      • Detailed webhook settings
      • How to check the webhook?
      • Incoming webhooks format
        • Incoming message
        • Sent message
        • Chats
        • Groups
        • Account and device status
        • Other
          • Presences
          • Views of stories (statuses)
          • Story (status) from your contacts
          • Calls
      • Receive messages
        • Receive WhatsApp messages using PHP
        • Receive WhatsApp messages using Node js
        • Receive WhatsApp messages using Python
    • HTTP API
      • Retrieve a Specific User's Chat History
      • Get a full-size picture in the response
      • Get order items
      • Get a profile picture of a chat or user
    • File expiration period
  • Groups
    • Send Group message
      • Mentioning all participants in a WhatsApp group
    • Get list of group members
    • Add new member to Group
  • Channels
    • Send post to WhatsApp Channel
    • Get messages from Channels
    • Get votes from polls in the Channel
  • Communities
    • Introduction
    • Create a community
    • Add a member to a community
    • Send announcement
    • Get info on community participants
    • Add a group / Exclude a group from the community
  • Account
    • Setting "Auto Download"
    • Customizable Webhook Headers
    • How to find out the IP channel
    • How to Delete a Channel
    • Add Business Info to Invoice
  • Source code
    • WhatsApp ChatBot
      • WhatsApp Python Bot
      • WhatsApp PHP Bot
      • WhatsApp Node JS Bot
      • WhatsApp Java Bot
    • WhatsApp API Google Sheets
    • WhatsApp Phone Number Checker
    • Request Distributor (Balancer)
  • FAQ
    • Chat ID. What is it and how to get it?
    • Current status of Buttons on WhatsApp
    • How to send a paragraph (line break)
    • Inactive Links in WhatsApp Messages
    • WhatsApp Text Formatting
    • Checking if the number has Whatsapp
    • Specifics of sending messages to numbers of different countries
    • Why aren't participants being added to the group?
  • Does WhatsApp API Work with the Phone Turned Off?
  • Hints
    • Android Emulators
    • Virtual Numbers for WhatsApp
    • How to use polls as buttons?
    • How to check who blocked you in Whatsapp?
    • Setting up a WhatsApp proxy
  • Integrations
    • Make.com
      • Ready-Made Scenarios
        • WhatsApp & Whisper API: Voice-to-Text Integration
        • Automated WhatsApp Group Message Forwarding in Make.com
      • Request Scenario Setup
    • Pabbly Connect
    • Google Contacts
    • DialogFlow
    • n8n
  • Tools
    • WhatsApp Number Checker
    • Automatic warm-up module
    • WhatsApp Activity Safety Meter
    • Residential Proxies from Whapi.Cloud
  • Troubleshooting
    • Couldn't Link Device – WhatsApp QR Code or Pairing Code Fails
    • Channel status “SYNC_ERROR”
    • Not getting a READ status on webhook
    • 429 (Too Many Requests) - Soft Ban
    • “Waiting for this message. This may take a while” – WhatsApp Message Error
    • Missing push notifications after connecting to API
  • Blocking
    • How to not get Banned?
    • How to do mailings without the risk of being blocked?
    • If My Number Is Banned, Can It Be Restored?
    • Unlocking Your WhatsApp Number
    • Connecting a New WhatsApp Number After a Ban: Steps and Recommendations
    • Warming Up New Phone Numbers for WhatsApp API
  • Partner Documentation
    • Introduction
    • Partner Dashboard Overview
    • Partner Program Guidelines
      • Workflow: Step-by-Step
      • Billing for Partners
      • Allocating Days to Customer Channels: Best Practices & Guide
      • Interface for channel management
    • Partner Documentation
      • Channel creation
      • Changing channel mode
      • Channel extension
      • Channel deletion
      • Getting the list of channels
      • Notices of end of days on balance
Powered by GitBook
On this page
  • Bot's source code
  • Getting Started

Was this helpful?

  1. Source code
  2. WhatsApp ChatBot

WhatsApp PHP Bot

Bot source code with basic functionality

PreviousWhatsApp Python BotNextWhatsApp Node JS Bot

Last updated 5 months ago

Was this helpful?

On you can find an implementation of a simple WhatsApp chatbot that demonstrates the basic functionality of sending and receiving messages of different types and working with groups.

Using this source code will allow you to customize the bot to your needs or take it as a basis for creating any other integration.

Bot's source code

Choose Your Bot Script

We offer two options for bot scripts:

  1. Basic Version (for Beginners)

This version is ideal if you're just starting with bot development. The bot responds to commands with text messages and image sharing, allowing you to focus on the core functionality without being overwhelmed by unnecessary features.

  1. Advanced Version (for Experienced Users)

This script comes with more capabilities, such as sending not just text messages but also videos, files, creating groups, and more. The code is more optimized and efficient, but it may not be as straightforward for beginners.

Here's what this bot does:

  • Respond to an unfamiliar command, this could be an instruction or your welcome message;

  • Send regular message;

  • Send image;

  • Send file;

  • Send video;

  • Send contact (vCard);

  • Send product;

  • Create new group, send an invitation and send message to the group;

  • Receive and reading incoming messages;

  • Webhook Setup;


Getting Started

Step 1: Install Composer

Composer is a dependency manager for PHP. To install it:

  1. Download and run Composer-Setup.exe for Windows or follow the installation instructions for MacOS or Linux.

Step 2: Install Dependencies

After installing Composer, install the necessary dependencies for your bot:

  1. Open the command line or terminal.

  2. Navigate to your project directory where the composer.json file is located.

  3. Run the command: composer install This reads the composer.json file, downloads the required libraries, and creates an autoload.php file that auto-loads all libraries in your project.

Step 3: Configure the Project

Configure your project settings:

  1. Open the config.php file in your IDE.

  2. Set up configurations such as your API token and webhook URL

Step 4: Launch the Bot

Now that dependencies are installed and the project is configured, you can launch the bot on your server or local machine. Ensure your server supports PHP and is accessible from the internet if you plan to use webhooks.


Multi-device Supported API: It's NOT necessary for the phone to be turned on or online for the bot to work. You can use the app as before.

If you need help, just message us in the support chat on any page of the site. We can help you with bot installation or customization.

Visit the official Composer website .

Learn more about how to configure the webhook to work locally here:

https://getcomposer.org
GitHub
LogoGitHub - Whapi-Cloud/whatsapp-simple-php-bot: Beginner-friendly WhatsApp bot in PHP: learn to build a basic bot that responds to commands with text and images. Simple setup, detailed code comments make it easy for new developers to master WhatsApp API integration and bot functionalityGitHub
Beginner-friendly WhatsApp bot in PHP
LogoGitHub - Whapi-Cloud/php-whatsapp-chatbot: WhatsApp PHP Bot. Basic functionality that the WhatsApp bot needs: send and receive messages, send image/file/docs/video, as well as creating a group and sending a message to the WhatsApp groupGitHub
How to test Webhook locally?