1
votes

I am working on a project which basically is a whatsapp-bot which is working fine as expected but the problem im going through is that.. The bot only work when the terminal is working and obviously I can't run my PC 24x7 . I need to make terminal run into the cloud .

Here is my index.js file :-

const axios = require('axios')

const { Client, LocalAuth, MessageMedia } = require('whatsapp-web.js');
const client = new Client({
    authStrategy : new LocalAuth()
});

client.on('qr', qr => {
    qrcode.generate(qr, {small: true});
});

client.on('ready', () => {
    console.log('Client is ready!');
});

client.on('message',async message => {
    const content = message.body
    if(content === 'meme plz') {
        const meme = await axios('https://meme-api.herokuapp.com/gimme')
        .then(res => res.data.url)
        client.sendMessage(message.from, await MessageMedia.fromUrl(meme))
    }
    else if(content === 'joke plz') {
        const joke = await axios('https://v2.jokeapi.dev/joke/Any?safe-mode')
        .then(res => res.data)

        const jokemsg = await client.sendMessage(message.from,joke.setup || joke.joke)
        if(joke.delivery) setTimeout(function(){jokemsg.reply(joke.delivery)},5000)
    }
    
});
client.on('message', message => {
    if(message.body === 'hi') {
        message.reply('hlo');
    }
});


client.initialize();

there is niether express nor used port . So where and how to deploy . If someone explain will be grate help.

here is my package.json

{
  "name": "whatsapp-bot",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "node index.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "axios": "^0.27.2",
    "nodemon": "^2.0.19",
    "qrcode-terminal": "^0.12.0",
    "whatsapp-web.js": "^1.17.1"
  }
}
you need to google it, there are lots of free platforms you can deploy your project, Stackoverflow will not recommend anything, your question is opinion based. - turivishal
I didn't got it but can i do with AWS ? - Apurv JHA
Yes, you can do it with AWS (and many other Providers). You can use something like EC2 for a start. There are great examples of how to run Node.js applications on EC2. Googling EC2 and Nodejs gives you a ton of great results. Maybe you will move to something else later but if you WANT to use AWS start of with EC2. - Lalaluka