Skip to content
Merged
1 change: 1 addition & 0 deletions App/CronJobs/cronJob.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const cron = require("node-cron");
// const express = require("express"); // import is not necessary since we will not run the job in this file.
// const fs = require("fs"); // we shall use this file-system module at a later stage when needed.
// const fs = require("fs"); // we shall you this file-system module at a later stage when needed.
const sendWhatsappMessage = require('../Whatsapp/whatsapp');
const telNumbers = require('../Whatsapp/numbers');
Expand Down
13 changes: 13 additions & 0 deletions App/Files/FilesUtility/readAndWriteToFiles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function* writeToTextFile() {
fs.writeFile('Output.txt', data, (err) => {

// In case of a error throw err.
if (err) throw err;
})
}

function readFromTextFile() {

}

module.exports = { writeToTextFile, readFromTextFile }
53 changes: 27 additions & 26 deletions App/Whatsapp/whatsapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,34 @@ const client = require('twilio')(accountSid, authToken);
const whatsappNumbers = require('./numbers')

// function that handles sending of the whatsapp messages
function sendWhatsappMessage (whatsappNumbers) {
function sendMessage(numbers) {
function sendWhatsappMessage(whatsappNumbers) {

// to handle multiple numbers we need to create this loop below
// sending a message to each number.
whatsappNumbers.forEach(num => {
// send message
client.messages
.create({
// body should be the message you are sending. you can insert anything you feel like
body: `Hello, this is an automated whatsapp message from Node webscrapper project. This message proves that the app is working fine`,
// for now we are using the twilio sandbox untill production then it can be changed
from: `whatsapp:${process.env.SANDBOX_WHATSAPP_NUMBER}`,
// THIS NUMBER IS KEPT AS AN ENVIRONMENTAL VARIABLE IN THE nodemon.json file, key is number
to: `whatsapp:${num}`
})
// resolve
.then(message => {
// message was sent successsfully
console.log(message._solution)
})
.catch(error => {
// an error occured and message was not sent
console.log(`An error occured ${error}`)
})
.done();
})
}
// to handle multiple numbers we need to create this loop below
// sending a message to each number.
whatsappNumbers.forEach(num => {
// send message
client.messages
.create({
// body should be the message you are sending. you can insert anything you feel like
body: `Hello, this is an automated whatsapp message from Node webscrapper project. This message proves that the app is working fine`,
// for now we are using the twilio sandbox untill production then it can be changed
from: `whatsapp:${process.env.SANDBOX_WHATSAPP_NUMBER}`,
// THIS NUMBER IS KEPT AS AN ENVIRONMENTAL VARIABLE IN THE nodemon.json file, key is number
to: `whatsapp:${num}`
})
// resolve
.then(message => {
// message was sent successsfully
console.log(message._solution)
})
.catch(error => {
// an error occured and message was not sent
console.log(`An error occured ${error}`)
})
.done();
})
}

// let's export the function here.
module.exports = sendWhatsappMessage;
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ We look forward to using this idea to be able to gather online analytics from di
---
run `npm install` or simply `npm i` to install dependencies for the application.

| Author | Github handle | Twitter handle |
| ------------- |:-------------:|
| Louis Musanje Michael | [louicoder](github.com/louicoder)|
#### CronJobs:
---
We automate a few tasks like sending emails, SMSs and whatsapp messages using this particualr feature. To start using the cron-job function, simply import the function you want to be executed into the croJob.js file and execute within the cronJob function
Expand All @@ -20,6 +23,8 @@ const cronJob = () => cron.schedule("*/10 * * * * *", function () {
sendMessage(telNumbers); // uncomment to send automated whtsapp messages here.
});

| Collaborators | Github handle | Twitter handle |
| ------------- |:-------------:|
Example:
========
0 8 * * * every day at 8am
Expand Down