Giter VIP home page Giter VIP logo

zain-ul-din / whatsapp-ai-bot Goto Github PK

View Code? Open in Web Editor NEW
163.0 5.0 88.0 34.61 MB

This is a WhatsApp AI bot that uses various AI models, including Gemini, GPT, DALL-E, and StabilityAI, to generate responses to user input.

Home Page: https://wa-ai-seven.vercel.app/

License: MIT License

Shell 0.44% TypeScript 99.13% C++ 0.43%
chatbot chatgpt chatgpt-api chatgpt-bot dalle dreamstudio stable-diffusion chat stability-ai whatsapp whatsapp-api whatsapp-bot whatsapp-web whatsapp-web-js puppeteer bot chatgpt-4 gemini open-source collaborate

whatsapp-ai-bot's Introduction

WhatsApp AI Bot πŸš€

The WhatsApp AI Bot is a chatbot that uses AI models APIs to generate responses to user input. The bot supports several AI models, including Gemini, Gemini-Vision, CHAT-GPT, DALL-E, and Stability AI, and users can also create their own models to customize the bot's behavior.

β™₯ Sponsor πŸ’Ž Bounty πŸš€ Deployment
link link link

Table of Content

Demo

Gemini

Screenshot (1186)

Stability AI + Chat-GPT

image

Dalle + Custom Model

image

Usage

1. Download Source Code

 git clone https://github.com/Zain-ul-din/WhatsApp-Ai-bot.git
 cd WhatsApp-Ai-bot

OR

2. Get API Keys

3. Add API Keys

  • create .env in the root of the project.

  • set following fields in .env file

 OPENAI_API_KEY=YOUR_OPEN_AI_API_KEY
 DREAMSTUDIO_API_KEY=YOUR_STABILITY_AI_API_KEY
 GEMINI_API_KEY=YOUR_GEMINI_API_KEY

4. Run the code

  • run setup.sh to start the bot.

  • Scan QR code.

Default Prefix

  • !gemini use gemini.
  • !gemini-vision use gemini-pro-vision model for images
  • !chatgpt use chat-gpt.
  • !dalle use Dalle.
  • !stable use Stability AI.
  • !bot use custom model.

Note! open src/whatsapp-ai.config.ts to edit config.

Docs Link

Tutorials

FQA

Disclaimer

This bot utilizes Puppeteer to operate an actual instance of Whatsapp Web to prevent blocking. However, it is essential to note that these operations come at a cost charged by OpenAI and Stability AI for every request made. Please be aware that WhatsApp does not support bots or unofficial clients on its platform, so using this method is not entirely secure and could lead to getting blocked.

Contributors

Sponsors

A big thank you to these people for supporting this project.

Levitco πŸ’Ž YOU?

About Us

This repository is maintained by Zain-Ul-Din

Show some ❀️ by starring this awesome repository!

Buy Me A Coffee

whatsapp-ai-bot's People

Contributors

dependabot[bot] avatar mikelcalvo avatar zain-ul-din avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

whatsapp-ai-bot's Issues

QR-Code Problem

Hello, is there a way to save the QR code to a image file?

I can't scan it with my mobile cuz it's not readable.

Look screenshot, pls.
Screenshot_2024-02-08-05-46-11-771_com server auditor ssh client

stability AI API Fix

Discussed in #26

Originally posted by levitco March 14, 2024
I just added the keys from the links i created both are working and with credit

βœ– StableDiffusionModel request fail | An error occur, at StabilityModel.ts sendMessage(prompt, msg) err: Error: The specified engine (ID stable-diffusion-v1) was not found.

βœ– GeminiModel request fail | An error occur, at ChatGptModel.ts sendMessage(prompt, msg) err: Error: [GoogleGenerativeAI Error]: Candidate was blocked due to RECITATION

image

Thanks for your time and the amazing repo

!!Update Gemini issues was time approval

Error: Invalid environment; fetch is not defined

ξΊ§ sh setup.sh
installing dependencies
Need to install the following packages:
[email protected]
Ok to proceed? (y) y
yarn install v1.22.19
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
Done in 47.12s.
npm notice
npm notice New major version of npm available! 8.19.2 -> 9.7.2
npm notice Changelog: https://github.com/npm/cli/releases/tag/v9.7.2
npm notice Run npm install -g [email protected] to update!
npm notice
βœ” dependencies has been installed
initializing server
yarn run v1.22.19
$ vite-node ./src/index.ts
πŸ€– starting client...
file:///home/runner/whatsapp-ai-bot/node_modules/chatgpt/build/index.js:174
throw new Error("Invalid environment; fetch is not defined");
^

Error: Invalid environment; fetch is not defined
at new ChatGPTAPI (file:///home/runner/whatsapp-ai-bot/node_modules/chatgpt/src/chatgpt-api.ts:107:13)
at new ChatGptModel (/home/runner/whatsapp-ai-bot/src/models/ChatGptModel.ts:15:23)
at new WhatsAppClient (/home/runner/whatsapp-ai-bot/src/lib/WhatsAppClient.ts:36:42)
at /home/runner/whatsapp-ai-bot/src/index.ts:4:24
at ViteNodeRunner.directRequest (file:///home/runner/whatsapp-ai-bot/node_modules/vite-node/dist/client.mjs:312:5)
at ViteNodeRunner.cachedRequest (file:///home/runner/whatsapp-ai-bot/node_modules/vite-node/dist/client.mjs:156:14)
at ViteNodeRunner.executeFile (file:///home/runner/whatsapp-ai-bot/node_modules/vite-node/dist/client.mjs:133:12)
at CAC.run (file:///home/runner/whatsapp-ai-bot/node_modules/vite-node/dist/cli.mjs:70:5)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

[Enhancement] - Using different prompts to signify which model to choose is strange.

You can make a single prompt and let your model choose which model will suit this input text.

Input

!bot Generate an image of a black cat with light green eyes

Note: Choose DALL-E automatically and generate an image.

Output

Input

!bot what is HTTP?

Note: Choose ChatGPT automatically.

Output

HTTP stands for Hypertext Transfer Protocol, which is a protocol used to transfer data over the internet. It is a standard application layer protocol that defines how data is transmitted between web servers and web browsers.

TypeError: data.id.id.substring is not a function

I encountered an error while running the code that utilizes the this program.

The error message indicates a TypeError at line 91 of the Message.js file.

/workspaces/whatsapp-ai-bot/node_modules/whatsapp-web.js/src/structures/Message.js:91
this.deviceType = data.id.id.length > 21 ? 'android' : data.id.id.substring(0, 2) == '3A' ? 'ios' : 'web';
^

TypeError: data.id.id.substring is not a function
at Message._patch (/workspaces/whatsapp-ai-bot/node_modules/whatsapp-web.js/src/structures/Message.js:91:75)
at new Message (/workspaces/whatsapp-ai-bot/node_modules/whatsapp-web.js/src/structures/Message.js:18:24)
at Client.sendMessage (/workspaces/whatsapp-ai-bot/node_modules/whatsapp-web.js/src/Client.js:699:16)
at processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v19.9.0
error Command failed with exit code 1.

if you can just explain to me ways to solve this issue i will be gratefull.

thank you

Put memory to the bot

It is a very good bot, it only needs to save the login and have chat memory, the only bad thing is that pupppeter does not work in some online apps, Replit.com

Latest whatsapp-web.js update

ith the latest whatsapp-web.js there seems to be a problem when loading chats. Because WWeb broke webcache, there was an special update

After QR has been generated, you receive the following messages:

User Authenticated!
loading chat...

And never stays there forever (in a loop). Chat never gets loaded and therefore, Client is never ready.

Any suggestion or help its appreciated.

RUST.2024.04.18.-.22.31.26.03.-.Trim.mp4

"TypeError during QR Code generation in WhatsApp AI Bot setup"

I runned this on the my local and codespaces

I encountered a TypeError while setting up the WhatsApp AI Bot. After successfully installing dependencies with Yarn and initiating the server, the process failed during the QR Code generation step. The error occurs in LocalWebCache.js of the whatsapp-web.js module when attempting to read a property of null. It seems like the regular expression used to find the version number in indexHtml isn't returning a match and hence the script is trying to access an index of a null object.
Here's the stack trace for the error:

TypeError: Cannot read properties of null (reading '1')
    at LocalWebCache.persist (/workspaces/whatsapp-ai-bot/node_modules/whatsapp-web.js/src/webCache/LocalWebCache.js:34:69)
    at /workspaces/whatsapp-ai-bot/node_modules/whatsapp-web.js/src/Client.js:744:36
    at processTicksAndRejections (node:internal/process/task_queues:95:5)

image

`@levitco ➜ /workspaces/whatsapp-ai-bot (master) $ bash ./setup.sh
installing dependencies
Need to install the following packages:
[email protected]
Ok to proceed? (y) y
yarn install v1.22.22
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
Done in 10.23s.
npm notice 
npm notice New minor version of npm available! 10.2.4 -> 10.5.1
npm notice Changelog: https://github.com/npm/cli/releases/tag/v10.5.1
npm notice Run npm install -g [email protected] to update!
npm notice 
βœ” dependencies has been installed
initializing server
yarn run v1.22.22
$ vite-node ./src/index.ts
πŸ€– starting client...
β ™ Whats App Client | generating QR Code... 
/workspaces/whatsapp-ai-bot/node_modules/whatsapp-web.js/src/webCache/LocalWebCache.js:34
        const version = indexHtml.match(/manifest-([\d\\.]+)\.json/)[1];
                                                                    ^

TypeError: Cannot read properties of null (reading '1')
    at LocalWebCache.persist (/workspaces/whatsapp-ai-bot/node_modules/whatsapp-web.js/src/webCache/LocalWebCache.js:34:69)
    at /workspaces/whatsapp-ai-bot/node_modules/whatsapp-web.js/src/Client.js:744:36
    at processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v20.11.1
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
@levitco ➜ /workspaces/whatsapp-ai-bot (master) $ `

not working??

βœ– ChatGPTModel request fail | An error occur, at ChatGptModel.ts sendMessage(prompt, msg) err: Error: OpenAI error 429: {
    "error": {
        "message": "You exceeded your current quota, please check your plan and billing details.",
        "type": "insufficient_quota",
        "param": null,
        "code": null
    }
}

/workspaces/whatsapp-ai-bot/node_modules/whatsapp-web.js/src/structures/Message.js:91
this.deviceType = data.id.id.length > 21 ? 'android' : data.id.id.substring(0, 2) == '3A' ? 'ios' : 'web';
^

TypeError: data.id.id.substring is not a function
at Message._patch (/workspaces/whatsapp-ai-bot/node_modules/whatsapp-web.js/src/structures/Message.js:91:75)
at new Message (/workspaces/whatsapp-ai-bot/node_modules/whatsapp-web.js/src/structures/Message.js:18:24)
at Client.sendMessage (/workspaces/whatsapp-ai-bot/node_modules/whatsapp-web.js/src/Client.js:699:16)
at processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v19.9.0
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

http://localhost:5173/

http://localhost:5173/ ERRO, after inserting the key keys it boots, but tries to open a window and gives an error, I don't know what to do, can you help: I wanted to do something more complete with your system, we can coopeer together: Teenho Csure we can be good partners here in Brazil, my contact, 5511984325192, call me please, you have great ideas, congratulations!

Issue with Puppeteer after scanning QR code

image

Hi Zain, seems like there was some of kind change that break the application. It was going all good until this morning when I tried. I wonder what happened. Are you facing the same thing?

Every time it says i cant do this but can provide you tips regarding that?

i managed to make it work but every time i ask something it says i can't do this but can provide you tips regarding how to do that, which makes it useless, however, official chatgpt on openai.com is very useful and it does everything we ask it. So seems like this one uses an old model may be, can you fix it?
and Btw how to stop the bot on codespace?

Tutorial to run on a Ubuntu Server?

Hi,
Can you make a tutorial "how to run this bot on a Ubuntu Server through SSH console", please?

Setup.sh is working but I can't leave the SSH Saison cuz Bot stopping always. (stableDiffusion don't works cuz a dependency don't works " stable-diffusion-v1 error in console")

Which pre settings and packages do I need to run it as service?

Latest whatsapp-web.js update

With the latest whatsapp-web.js there seems to be a problem when loading chats. Because WWeb broke webcache, there was an special update for this: github:pedroslopez/whatsapp-web.js#webpak-exodus

After QR has been generated, you receive the following messages:
User Authenticated!
User Authenticated!
loading chat...

And never stays there forever (in a loop). Chat never gets loaded and therefore, Client is never ready.

Any suggestion or help its appreciated.

Version 3.0 Iteration Plan

General proposal

  • Implementation of web interface & bind data with front-end using web-sockets
  • generate QR code on the web instead of the terminal since many users facing #21
  • display conversation on the front-end application.
  • Allow users to add API keys from the front-end application and store credentials in local DB.
  • Implement rate-limiting, include-sender, exclude-sender features for each AI model.

Definitions

  • rate-limiting determines how many requests a sender can send for a given number of times. for example: User X can send 10 requests per min. #23
  • include-sender allows sender only if 'include-sender' list contains the sender number
  • exclude-sender disallows sender if 'exclude-sender' list contains the sender number

Get Started

fork this branch to contribute.

Can't generate QR code on headless ubuntu server

Github codespace limit exceeded so trying to set this up on ubuntu server but as it has no chromium installed giving this error,

πŸ€– starting client...
β ‹ Whats App Client | generating QR Code...
/home/WhatsApp-Ai-bot/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:241
            reject(new Error([
                   ^

Error: Failed to launch the browser process!

Can QR code be shared via any other way?

Problem

If you remove the prefix, the AI ​​responds itself

Model's maximum context length exceed

Thank you for providing the whatsapp-ai-bot. I tested it and it's a great application. However, I encountered the following issue during the trial. Whenever I engage in a few rounds of chat, I receive the following error. Is this a bug in the program or is there something that needs to be adjusted? Please advise.

 βœ– CustomModel request fail | An error occur, at CustomModel.ts sendMessage(prompt, msg) err: Error: OpenAI error 400: {
    | ^
  2 | "error": {
  3 | "message": "This model's maximum context length is 4097 tokens. However, you requested 4246 tokens (1246 in the messages, 3000 in the completion). Please reduce the length of the messages or completion.",
  4 | "type": "invalid_request_error",

after login getting err

βœ” QR has been generated! | Scan QR Code with you're mobile.
β ‹ loading chat...
/root/whatsapp-ai-bot/node_modules/puppeteer/lib/cjs/puppeteer/common/ExecutionContext.js:221
throw new Error('Evaluation failed: ' + helper_js_1.helper.getExceptionMessage(exceptionDetails));
^

Error: Evaluation failed: TypeError: Cannot read properties of undefined (reading 'default')
at puppeteer_evaluation_script:5:95
at ExecutionContext._evaluateInternal (/root/whatsapp-ai-bot/node_modules/puppeteer/src/common/ExecutionContext.ts:273:13)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at ExecutionContext.evaluate (/root/whatsapp-ai-bot/node_modules/puppeteer/src/common/ExecutionContext.ts:140:12)
at Client.initialize (/root/whatsapp-ai-bot/node_modules/whatsapp-web.js/src/Client.js:323:9)

Node.js v18.17.1
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
root@thunder:~/whatsapp-ai-bot#

insert my custom informations to reply to my costumers

Hello!
Im trying to check if is possible to let your project like this one:
https://www.youtube.com/watch?v=Sh94c6yn5aQ

It seem like you have almost everything done, im just trying to insert my custom informations like this guy did and after this interact with my whatsapp Business. is it possible?

i've created my .env file and also connected with my whatsapp through qrcode generated, so in my terminal i have this message:
QR has been generated! | Scan QR Code with you're mobile.
βœ” User Authenticated!
βœ” Client is ready | All set!
after that, i dont know what more can i do to reach this level above sent.

thank you so much!

Command failed with exit code 1.

[1/3] ⠁ puppeteer
[2/3] ⠁ puppeteer
error /root/WhatsApp-Ai-bot/node_modules/whatsapp-web.js/node_modules/puppeteer: Command failed.
Exit code: 1
Command: node install.js
Arguments:
Directory: /root/WhatsApp-Ai-bot/node_modules/whatsapp-web.js/node_modules/puppeteer
Output:
The chromium binary is not available for arm64.
If you are on Ubuntu, you can install with:

sudo apt install chromium

sudo apt install chromium-browser

/root/WhatsApp-Ai-bot/node_modules/whatsapp-web.js/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserFetcher.js:119
throw new Error();
^

Error
at /root/WhatsApp-Ai-bot/node_modules/whatsapp-web.js/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserFetcher.js:119:27
at FSReqCallback.oncomplete (node:fs:198:21)

Node.js v22.3.0

βœ” dependencies has been installed
initializing server
yarn run v1.22.22
warning ../package.json: No license field
$ vite-node ./src/index.ts
node:internal/dns/promises:86
this.reject(new DNSException(err, 'getaddrinfo', this.hostname));
^

Error: getaddrinfo ENOTFOUND localhost
at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:internal/dns/promises:86:17) {
errno: -3007,
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'localhost'
}

Node.js v22.3.0
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.