DEV Community

parmarjatin4911@gmail.com
parmarjatin4911@gmail.com

Posted on

Build a WhatsApp ChatGPT-powered AI chatbot for your business

Build a WhatsApp ChatGPT-powered AI chatbot for your business

Turn your WhatsApp number into a ChatGPT-powered AI powerful chatbot in minutes with this tutorial, using the Node.js, OpenAI ChatGPT and Wassenger API.

By following this tutorial you will be able to have a fully functional ChatGPT-like AI chatbot running in minutes on your computer or cloud server that behaves like a virtual customer support assistant for a specific business purpose.

You can easily customize and instruct the AI bot to adjust its behaviour, role, purpose and knowledge boundaries. Also, the AI bot will be conversation-aware based on your previous message history with the user on WhatsApp, enabling more context-specific accurate responses.

The chatbot will be able to understand and speak many languages and has been trained to behave like a customer support virtual assistant specialized in certain tasks.

Additionally, you can easily augment domain-specific knowledge about your business in real-time by using function actions that let the AI bot arbitrarily communicate with your code functions or remote APIs to retrieve and feed the AI with custom information. Find an example here.

The code for this tutorial is available on GitHubπŸ’»

You can also run the bot program right from your browser without installing any software or code by clicking here πŸŽ‰

🀩 πŸ€– Wassenger is a complete WhatsApp API solution. Sign up for a 7-day free trial and get started in minutes!

🀩 πŸ€– Wassenger is a complete WhatsApp API solution. Sign up for a 7-day free trial and get started in minutes!
Enter fullscreen mode Exit fullscreen mode

Contents

How it works
Features
Bot behavior
Requirements
Project structure
Installation
Configuration
Customization
Run the bot
Usage
Questions

πŸ€‘ πŸ’° Earn 30% comission by referring users to Wassenger. Get your referral link now. Terms apply.
Enter fullscreen mode Exit fullscreen mode

How it works

  1. Starts a web service that automatically connects to the Wassenger API and your WhatsApp number

  2. Create a tunnel using Ngrok to be able to receive Webhook events on your computer (or you can use a dedicated Webhook URL instead if you run the bot program in your cloud server).

  3. Registers the webhook endpoint automatically to receive incoming messages.

  4. Processes and replies to messages received using a ChatGPT-powered AI model trained with custom instructions.

  5. You can start playing with the AI bot by sending messages to the Wassenger-connected WhatsApp number.
    Features

This tutorial provides a complete ChatGPT-powered AI chatbot implementation in Node.js that:

Provides a fully featured chatbot in your WhatsApp number connected to Wassenger
Replies automatically to any incoming messages from arbitrary users
Can understand any text in natural language and reply in 90+ different human languages
Allows any user to ask to talk with a human, in which case the chat will be assigned to an agent and exit the bot flow
AI bot behaviour can be easily adjusted in the configuration file (open config.js)
Enter fullscreen mode Exit fullscreen mode

Bot behavior

The AI bot will always reply to inbound messages based on the following criteria:

The chat belongs to a user (group chats are always ignored)
The chat is not assigned to any agent inside Wassenger
The chat has not any of the blacklisted labels (see config.js)
The chat user number has not been blacklisted (see config.js)
The chat or contact has not been archived or blocked
If a chat is unassigned from an agent, the bot will take over it again and automatically reply to new incoming messages
Enter fullscreen mode Exit fullscreen mode

Requirements

Node.js >= v16 β€” Download it here
WhatsApp Personal or Business number
OpenAI API key β€” Sign up for free
Wassenger API key β€” Sign up for free
Connect your WhatsApp Personal or Business number to Wassenger
Sign up for a Ngrok free account to create a webhook tunnel (only if running the program on your local computer)
Enter fullscreen mode Exit fullscreen mode

Project structure

Browse the source files on GitHub

\
|- bot.js -> the bot source code in a single file
|- config.js -> configuration file to customize credentials and bot behavior
|- actions.js -> functions to perform actions through the Wassenger API
|- server.js -> initializes the web server to process webhook events
|- main.js -> initializes the bot server and creates the webhook tunnel (when applicable)
|- store.js -> the bot source code in a single file
|- package.json -> node.js package manifest required to install dependencies
|- node_modules -> where the project dependencies will be installed, managed by npm

Installation

If you have git installed, run the following command from the Terminal:

git clone https://github.com/wassengerhq/whatsapp-chatgpt-bot.git

If you don’t have git, download the project source files here and unzip it.

Top comments (0)