├── features └── meme.js ├── .gitignore ├── .github └── ISSUE_TEMPLATE │ ├── custom.md │ ├── feature_request.md │ └── bug_report.md ├── SECURITY.md ├── package.json ├── LICENSE ├── CONTRIBUTING.md ├── README.md ├── CODE_OF_CONDUCT.md └── index.js /features/meme.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ffmpeg 2 | node_modules 3 | package-lock.json 4 | .env 5 | .wwebjs_auth 6 | downloaded-media -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/custom.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Custom issue template 3 | about: Describe this issue template's purpose here. 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | 11 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Supported Versions 4 | 5 | Use this section to tell people about which versions of your project are 6 | currently being supported with security updates. 7 | 8 | | Version | Supported | 9 | | ------- | ------------------ | 10 | | 5.1.x | :white_check_mark: | 11 | | 5.0.x | :x: | 12 | | 4.0.x | :white_check_mark: | 13 | | < 4.0 | :x: | 14 | 15 | ## Reporting a Vulnerability 16 | 17 | Use this section to tell people how to report a vulnerability. 18 | 19 | Tell them where to go, how often they can expect to get an update on a 20 | reported vulnerability, what to expect if the vulnerability is accepted or 21 | declined, etc. 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "whatsapp-bot", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "dev": "nodemon index.js", 8 | "start": "node index", 9 | "test": "echo \"Error: no test specified\" && exit 1" 10 | }, 11 | "keywords": [], 12 | "author": "", 13 | "license": "ISC", 14 | "dependencies": { 15 | "axios": "^1.3.4", 16 | "dotenv": "^16.0.3", 17 | "mime-types": "^2.1.35", 18 | "mongoose": "^7.0.2", 19 | "openai": "^3.2.1", 20 | "qrcode-terminal": "^0.12.0", 21 | "sharp": "^0.31.3", 22 | "wa-sticker-formatter": "^4.4.4", 23 | "whatsapp-web.js": "^1.19.4", 24 | "wwebjs-mongo": "^1.1.0" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to WhatsApp Bot with Chatbot, DALLE-2, Meme Generation, and Image-to-Sticker Conversion 2 | 3 | Thank you for your interest in contributing to this project! As an open-source project, we welcome contributions from anyone. By contributing to this project, you are agreeing to abide by the Code of Conduct. 4 | 5 | ## Getting Started 6 | 1. Fork the repository 7 | 2. Clone the repository to your local machine 8 | 3. Install the necessary dependencies by running `npm install` 9 | 4. Create a new branch for your changes using `git checkout -b feature/your-feature-name` 10 | 5. Make your changes and commit them with a descriptive commit message 11 | 6. Push your changes to your forked repository 12 | 7. Create a pull request to the main repository's develop branch 13 | 14 | ## Issues 15 | If you notice a bug or want to request a new feature, please create an issue on the GitHub repository. Please include as much detail as possible, including how to reproduce the issue and any error messages that you encounter. 16 | 17 | ## Pull Requests 18 | When submitting a pull request, please ensure that your changes: 19 | - Follow the existing coding style 20 | - Include tests for any new functionality 21 | - Include documentation updates as necessary 22 | 23 | Please also make sure that your code builds and passes the existing tests. 24 | 25 | ## Code of Conduct 26 | Please review our [Code of Conduct](./CODE_OF_CONDUCT.md) before contributing to this project. 27 | 28 | ## License 29 | By contributing to this project, you agree that your contributions will be licensed under the MIT License. 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WhatsApp Bot with ChaGPT🔥, DALLE-2⚡,Meme Generation, and Image-to-Sticker Conversion 2 | 3 | This is a Node.js-based chatbot built using the whatsapp-web.js library that allows users to search the internet, get quotes, and create stickers from images. The chatbot can be used on any WhatsApp-enabled device. 4 | 5 | ## Features 6 | 7 | - DALLE-2: The bot can generate images using DALLE-2 neural network. 8 | - Meme Generation: The bot can generate memes on the fly using popular templates and user-provided captions. 9 | - Image-to-Sticker Conversion: Users can upload images to the bot, which will then convert them to high-quality stickers that can be shared in chats. 10 | - Multi-Feature Bot: The bot combines all of these features into a single, powerful package that can enhance any WhatsApp group or chat. 11 | - Search the internet for any topic or question using `-search` 12 | - Get random quotes using `-quote` 13 | - Create stickers from images using `-sticker` 14 | - Get a random meme using `-meme` 15 | - Get help using `-help` 16 | - Get information about the chatbot using `-about` 17 | 18 | ## Installation 19 | 20 | 1. Clone the repository 21 | 2. Install the required packages by running `npm install` 22 | 3. Create a `.env` file with the following keys: 23 | - `MONGODB_URI`: MongoDB connection string 24 | - `API_KEY`: OpenAI API key 25 | 4. Run `npm start` to start the chatbot 26 | 27 | ### Create .env File: 28 | 29 | ```sh 30 | API_KEY= 31 | MONGODB_URI= 32 | ``` 33 | 34 | ## Usage 35 | 36 | 1. Save the chatbot's phone number in your contacts 37 | 2. Scan the QR code that is displayed in the console using your WhatsApp app 38 | 3. Send a message to the chatbot to start using it 39 | 40 | ## Dependencies 41 | 42 | - `whatsapp-web.js` for the WhatsApp API 43 | - `dotenv` for environment variables 44 | - `axios` for making API requests 45 | - `qrcode-terminal` for displaying the QR code 46 | - `mime-types` for getting the file extension of media files 47 | - `path` and `fs` for handling files 48 | - `openai` for the search functionality 49 | - `wwebjs-mongo` and `mongoose` for the database 50 | 51 | ## Contributing 52 | 53 | Thank you for your interest in contributing to this project! As an open-source project, we welcome contributions from anyone. By contributing to this project, you are agreeing to abide by the Code of Conduct. 54 | 55 | ## Getting Started 56 | 1. Fork the repository 57 | 2. Clone the repository to your local machine 58 | 3. Install the necessary dependencies by running `npm install` 59 | 4. Create a new branch for your changes using `git checkout -b feature/your-feature-name` 60 | 5. Make your changes and commit them with a descriptive commit message 61 | 6. Push your changes to your forked repository 62 | 7. Create a pull request to the main repository's develop branch 63 | 64 | ## Issues 65 | If you notice a bug or want to request a new feature, please create an issue on the GitHub repository. Please include as much detail as possible, including how to reproduce the issue and any error messages that you encounter. 66 | 67 | ## Pull Requests 68 | When submitting a pull request, please ensure that your changes: 69 | - Follow the existing coding style 70 | - Include tests for any new functionality 71 | - Include documentation updates as necessary 72 | 73 | Please also make sure that your code builds and passes the existing tests. 74 | 75 | ## Code of Conduct 76 | Please review our [Code of Conduct](./CODE_OF_CONDUCT.md) before contributing to this project. 77 | 78 | ## License 79 | By contributing to this project, you agree that your contributions will be licensed under the MIT License. 80 | 81 | ## License 82 | 83 | This project is licensed under the MIT License. 84 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | We as members, contributors, and leaders pledge to make participation in our 6 | community a harassment-free experience for everyone, regardless of age, body 7 | size, visible or invisible disability, ethnicity, sex characteristics, gender 8 | identity and expression, level of experience, education, socio-economic status, 9 | nationality, personal appearance, race, religion, or sexual identity 10 | and orientation. 11 | 12 | We pledge to act and interact in ways that contribute to an open, welcoming, 13 | diverse, inclusive, and healthy community. 14 | 15 | ## Our Standards 16 | 17 | Examples of behavior that contributes to a positive environment for our 18 | community include: 19 | 20 | * Demonstrating empathy and kindness toward other people 21 | * Being respectful of differing opinions, viewpoints, and experiences 22 | * Giving and gracefully accepting constructive feedback 23 | * Accepting responsibility and apologizing to those affected by our mistakes, 24 | and learning from the experience 25 | * Focusing on what is best not just for us as individuals, but for the 26 | overall community 27 | 28 | Examples of unacceptable behavior include: 29 | 30 | * The use of sexualized language or imagery, and sexual attention or 31 | advances of any kind 32 | * Trolling, insulting or derogatory comments, and personal or political attacks 33 | * Public or private harassment 34 | * Publishing others' private information, such as a physical or email 35 | address, without their explicit permission 36 | * Other conduct which could reasonably be considered inappropriate in a 37 | professional setting 38 | 39 | ## Enforcement Responsibilities 40 | 41 | Community leaders are responsible for clarifying and enforcing our standards of 42 | acceptable behavior and will take appropriate and fair corrective action in 43 | response to any behavior that they deem inappropriate, threatening, offensive, 44 | or harmful. 45 | 46 | Community leaders have the right and responsibility to remove, edit, or reject 47 | comments, commits, code, wiki edits, issues, and other contributions that are 48 | not aligned to this Code of Conduct, and will communicate reasons for moderation 49 | decisions when appropriate. 50 | 51 | ## Scope 52 | 53 | This Code of Conduct applies within all community spaces, and also applies when 54 | an individual is officially representing the community in public spaces. 55 | Examples of representing our community include using an official e-mail address, 56 | posting via an official social media account, or acting as an appointed 57 | representative at an online or offline event. 58 | 59 | ## Enforcement 60 | 61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 62 | reported to the community leaders responsible for enforcement at 63 | adityakumarverified@gmail.com. 64 | All complaints will be reviewed and investigated promptly and fairly. 65 | 66 | All community leaders are obligated to respect the privacy and security of the 67 | reporter of any incident. 68 | 69 | ## Enforcement Guidelines 70 | 71 | Community leaders will follow these Community Impact Guidelines in determining 72 | the consequences for any action they deem in violation of this Code of Conduct: 73 | 74 | ### 1. Correction 75 | 76 | **Community Impact**: Use of inappropriate language or other behavior deemed 77 | unprofessional or unwelcome in the community. 78 | 79 | **Consequence**: A private, written warning from community leaders, providing 80 | clarity around the nature of the violation and an explanation of why the 81 | behavior was inappropriate. A public apology may be requested. 82 | 83 | ### 2. Warning 84 | 85 | **Community Impact**: A violation through a single incident or series 86 | of actions. 87 | 88 | **Consequence**: A warning with consequences for continued behavior. No 89 | interaction with the people involved, including unsolicited interaction with 90 | those enforcing the Code of Conduct, for a specified period of time. This 91 | includes avoiding interactions in community spaces as well as external channels 92 | like social media. Violating these terms may lead to a temporary or 93 | permanent ban. 94 | 95 | ### 3. Temporary Ban 96 | 97 | **Community Impact**: A serious violation of community standards, including 98 | sustained inappropriate behavior. 99 | 100 | **Consequence**: A temporary ban from any sort of interaction or public 101 | communication with the community for a specified period of time. No public or 102 | private interaction with the people involved, including unsolicited interaction 103 | with those enforcing the Code of Conduct, is allowed during this period. 104 | Violating these terms may lead to a permanent ban. 105 | 106 | ### 4. Permanent Ban 107 | 108 | **Community Impact**: Demonstrating a pattern of violation of community 109 | standards, including sustained inappropriate behavior, harassment of an 110 | individual, or aggression toward or disparagement of classes of individuals. 111 | 112 | **Consequence**: A permanent ban from any sort of public interaction within 113 | the community. 114 | 115 | ## Attribution 116 | 117 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 118 | version 2.0, available at 119 | https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 120 | 121 | Community Impact Guidelines were inspired by [Mozilla's code of conduct 122 | enforcement ladder](https://github.com/mozilla/diversity). 123 | 124 | [homepage]: https://www.contributor-covenant.org 125 | 126 | For answers to common questions about this code of conduct, see the FAQ at 127 | https://www.contributor-covenant.org/faq. Translations are available at 128 | https://www.contributor-covenant.org/translations. 129 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const { Client, RemoteAuth, MessageMedia } = require("whatsapp-web.js"); 2 | const dotenv = require("dotenv"); 3 | dotenv.config(); 4 | const axios = require("axios"); 5 | const qrcode = require("qrcode-terminal"); 6 | const mime = require("mime-types"); 7 | const path = require("path"); 8 | const fs = require("fs"); 9 | // Require database 10 | const { MongoStore } = require("wwebjs-mongo"); 11 | const mongoose = require("mongoose"); 12 | dotenv.config(); 13 | 14 | const { Configuration, OpenAIApi } = require("openai"); 15 | 16 | const configuration = new Configuration({ 17 | apiKey: process.env.API_KEY, 18 | }); 19 | const openai = new OpenAIApi(configuration); 20 | 21 | // Meme Function 22 | const sendMeme = async (chat) => { 23 | try { 24 | const response = await axios.get("https://meme-api.com/gimme"); 25 | const memeUrl = response.data.url; 26 | const memeCaption = response.data.title; 27 | 28 | const caption = memeCaption || ""; 29 | const media = await MessageMedia.fromUrl(memeUrl); 30 | await chat.sendMessage(media, { caption }); 31 | } catch (error) { 32 | console.error(error); 33 | } 34 | }; 35 | 36 | // Load the session data 37 | mongoose.connect(process.env.MONGODB_URI).then(() => { 38 | const store = new MongoStore({ mongoose: mongoose }); 39 | const client = new Client({ 40 | authStrategy: new RemoteAuth({ 41 | store: store, 42 | backupSyncIntervalMs: 1000000, 43 | }), 44 | }); 45 | 46 | // QR Code 47 | client.on("qr", (qr) => { 48 | qrcode.generate(qr, { small: true }); 49 | }); 50 | 51 | client.on("ready", () => { 52 | console.log("Client is ready!"); 53 | }); 54 | client.on("remote_session_saved", () => { 55 | console.log("Remote session saved"); 56 | }); 57 | 58 | client.on("message", async (message) => { 59 | let chat = await message.getChat(); 60 | 61 | // Group Chat 62 | if (chat.isGroup) { 63 | let grpid = chat.id._serialized; 64 | console.log("Group ID: " + grpid); 65 | 66 | if (message.body === "-sticker") { 67 | if (message.hasMedia) { 68 | message.downloadMedia().then((media) => { 69 | if (media) { 70 | const mediaPath = "./downloaded-media/"; 71 | 72 | if (!fs.existsSync(mediaPath)) { 73 | fs.mkdirSync(mediaPath); 74 | } 75 | 76 | const extension = mime.extension(media.mimetype); 77 | 78 | const filename = new Date().getTime(); 79 | 80 | const fullFilename = mediaPath + filename + "." + extension; 81 | 82 | // Save to file 83 | try { 84 | fs.writeFileSync(fullFilename, media.data, { 85 | encoding: "base64", 86 | }); 87 | console.log("File downloaded successfully!", fullFilename); 88 | console.log(fullFilename); 89 | MessageMedia.fromFilePath((filePath = fullFilename)); 90 | 91 | client.sendMessage( 92 | message.from, 93 | new MessageMedia(media.mimetype, media.data, filename), 94 | { 95 | sendMediaAsSticker: true, 96 | } 97 | ); 98 | fs.unlinkSync(fullFilename); 99 | console.log(`File Deleted successfully!`); 100 | } catch (err) { 101 | console.log("Failed to save the file:", err); 102 | console.log(`File Deleted successfully!`); 103 | } 104 | } 105 | }); 106 | } else { 107 | message.reply(`send image with caption *-sticker* `); 108 | } 109 | } else if (message.body === "-quote") { 110 | const apiData = await axios.get("https://type.fit/api/quotes"); 111 | const randomNumber = Math.floor(Math.random() * apiData.data.length); 112 | message.reply(`*${apiData.data[randomNumber].text}*`); 113 | } else if (message.body === "-ping") { 114 | return message.reply("pong"); 115 | } else if (message.body === "-meme") { 116 | try { 117 | const chat = await client.getChatById(message.from); 118 | await sendMeme(chat); 119 | } catch (err) { 120 | console.log(err); 121 | } 122 | } else if (message.body.startsWith("-search")) { 123 | try { 124 | const prompt = message.body.substring(8); 125 | const response = await openai.createCompletion({ 126 | model: "text-davinci-003", 127 | prompt: `tell me ${prompt}`, 128 | temperature: 0.7, 129 | max_tokens: 3000, 130 | top_p: 1.0, 131 | frequency_penalty: 0.2, 132 | presence_penalty: 0, 133 | }); 134 | 135 | return await message.reply( 136 | response.data.choices[0].text.substring(2) 137 | ); 138 | } catch (err) { 139 | await message.reply("Something went wrong"); 140 | console.log(err); 141 | } 142 | } else if (message.body === "-ping") { 143 | return message.reply("pong"); 144 | } else if (message.body === "-help") { 145 | return message.reply( 146 | "Hi, I am a bot that can help you search the internet. To use me, just type -search and then your question. For example, -search what is the capital of India?" 147 | ); 148 | } else if (message.body === "-about") { 149 | return message.reply( 150 | "Hi, I am a bot that can help you search the internet. To use me, just type -search and then your question. For example, -search what is the capital of India?" 151 | ); 152 | } else if (message.body === "-test") { 153 | return message.reply( 154 | "Hi, I am a bot that can help you search the internet. To use me, just type -search and then your question. For example, -search what is the capital of India?" 155 | ); 156 | } else if (message.body === "-commands") { 157 | return message.reply( 158 | `-search 159 | -meme 160 | -quote 161 | -help 162 | -about 163 | -sticker 164 | -commands 165 | -image ` 166 | ); 167 | } else if (message.body.startsWith("-imagine")) { 168 | try { 169 | const prompt = message.body.substring(7); 170 | const response = await openai.createImage({ 171 | prompt: prompt, 172 | n: 1, 173 | size: "1024x1024", 174 | }); 175 | image_url = response.data.data[0].url; 176 | 177 | const media = await MessageMedia.fromUrl(image_url); 178 | return await client.sendMessage(message.from, message.reply(media)); 179 | } catch (error) { 180 | await message.reply("Something went wrong"); 181 | console.log(error); 182 | } 183 | } 184 | } 185 | 186 | // Personal Chat 187 | if (!chat.isGroup) { 188 | if (message.hasMedia) { 189 | message.downloadMedia().then((media) => { 190 | if (media) { 191 | try { 192 | const mediaPath = "./downloaded-media/"; 193 | 194 | if (!fs.existsSync(mediaPath)) { 195 | fs.mkdirSync(mediaPath); 196 | } 197 | 198 | const extension = mime.extension(media.mimetype); 199 | 200 | const filename = new Date().getTime(); 201 | 202 | const fullFilename = mediaPath + filename + "." + extension; 203 | 204 | // Save to file 205 | try { 206 | fs.writeFileSync(fullFilename, media.data, { 207 | encoding: "base64", 208 | }); 209 | console.log("File downloaded successfully!", fullFilename); 210 | console.log(fullFilename); 211 | MessageMedia.fromFilePath((filePath = fullFilename)); 212 | 213 | client.sendMessage( 214 | message.from, 215 | new MessageMedia(media.mimetype, media.data, filename), 216 | { 217 | sendMediaAsSticker: true, 218 | } 219 | ); 220 | fs.unlinkSync(fullFilename); 221 | console.log(`File Deleted successfully!`); 222 | } catch (err) { 223 | console.log("Failed to save the file:", err.message); 224 | console.log(`File Deleted successfully!`); 225 | } 226 | } catch (err) { 227 | console.log(err.message); 228 | } 229 | } 230 | }); 231 | } else if (message.body === "-quote") { 232 | const apiData = await axios.get("https://type.fit/api/quotes"); 233 | const randomNumber = Math.floor(Math.random() * apiData.data.length); 234 | message.reply(`*${apiData.data[randomNumber].text}*`); 235 | } else if (message.body === "-ping") { 236 | return message.reply("pong"); 237 | } else if (message.body === "-meme") { 238 | try { 239 | const chat = await client.getChatById(message.from); 240 | await sendMeme(chat); 241 | } catch (err) { 242 | console.log(err); 243 | } 244 | } else if (message.body.startsWith("-search")) { 245 | try { 246 | const prompt = message.body.substring(8); 247 | const response = await openai.createCompletion({ 248 | model: "text-davinci-003", 249 | prompt: `tell me ${prompt}`, 250 | temperature: 0.7, 251 | max_tokens: 3000, 252 | top_p: 1.0, 253 | frequency_penalty: 0.2, 254 | presence_penalty: 0, 255 | }); 256 | 257 | return await message.reply(response.data.choices[0]); 258 | } catch (err) { 259 | console.log(err); 260 | } 261 | } else if (message.body === "-ping") { 262 | return message.reply("pong"); 263 | } else if (message.body === "-help") { 264 | return message.reply( 265 | "Hi, I am a bot that can help you search the internet. To use me, just type -search and then your question. For example, -search what is the capital of India?" 266 | ); 267 | } else if (message.body === "-about") { 268 | return message.reply( 269 | "Hi, I am a bot that can help you search the internet. To use me, just type -search and then your question. For example, -search what is the capital of India?" 270 | ); 271 | } else if (message.body === "-test") { 272 | return message.reply( 273 | "Hi, I am a bot that can help you search the internet. To use me, just type -search and then your question. For example, -search what is the capital of India?" 274 | ); 275 | } else if (message.body === "-commands") { 276 | return message.reply( 277 | `-search 278 | -meme 279 | -quote 280 | -help 281 | -about 282 | -sticker 283 | -commands 284 | -imagine ` 285 | ); 286 | } else if (message.body.startsWith("-imagine")) { 287 | try { 288 | const prompt = message.body.substring(7); 289 | const response = await openai.createImage({ 290 | prompt: prompt, 291 | n: 1, 292 | size: "1024x1024", 293 | }); 294 | image_url = response.data.data[0].url; 295 | 296 | const media = await MessageMedia.fromUrl(image_url); 297 | return await client.sendMessage(message.from, message.reply(media)); 298 | } catch (error) { 299 | await message.reply("Something went wrong"); 300 | console.log(error); 301 | } 302 | } else if ( 303 | !message.body === "-sticker" || 304 | !message.body === "-quote" || 305 | !message.body === "-ping" || 306 | !message.body === "-help" || 307 | !message.body === "-about" || 308 | !message.body === "-test" || 309 | !message.body === "-commands" || 310 | !message.body.startsWith("-imagine") 311 | ) { 312 | try { 313 | const prompt = message.body; 314 | const response = await openai.createCompletion({ 315 | model: "text-davinci-003", 316 | prompt: prompt, 317 | temperature: 0.7, 318 | max_tokens: 3000, 319 | top_p: 1.0, 320 | frequency_penalty: 0.2, 321 | presence_penalty: 0, 322 | }); 323 | return await message.reply(response.data.choices[0].text); 324 | } catch (err) { 325 | await message.reply("Something went wrong"); 326 | console.log(err); 327 | } 328 | } 329 | } 330 | }); 331 | 332 | client.initialize(); 333 | }); 334 | 335 | const connection = mongoose.connection; 336 | 337 | connection.once("open", () => { 338 | console.log("MongoDB database connection established successfully"); 339 | }); 340 | --------------------------------------------------------------------------------