Build a WhatsApp Chatbot using PHP

building chatbot it’s very easy with Ultramsg API, you can build a customer service bot and best ai chatbot Through simple steps using the PHP language.

Chatbot 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 .
  • Sending Random Sentence .
  • Sending Random Joke .
  • Sending Random Image .

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 .

webhook json format

To see how the received JSON will look this video.

EXAMPLE JSON RESPONSE

{
  "event_type": "message_received",
  "instanceId": "90",
  "data": {
    "id": "[email protected]_7ECAED9EB68D3474BE591443134C2E3F",
    "from": "[email protected]",
    "to": "[email protected]",
    "ack": "pending",
    "type": "chat",
    "body": "I can't send a message using php code\nCan you help me",
    "fromMe": false,
    "isForwarded": false,
    "time": 1643311467
  }
}

Run a WhatsApp Chatbot

step 1 :

download project files from Github.

and put your instance ID and Token in example.php

new ultraMsgChatBot("token", "instance_id");

step 2 :

activate the “Webhook on Received” option and Set URL Webhook in Instance settings in ultramsg for example https://yourwebsite.com/chatbot/example.php

Set URL Webhook in Instance settings

step 3 :

Upload the bot project to your server or website.

** Congratulations.. you can now talk to your bot **