From fc966644ef44301df5521249e7092bb15c5bbcea Mon Sep 17 00:00:00 2001 From: Mohammed Ashab Uddin Date: Tue, 21 Jul 2020 13:56:06 +0400 Subject: [PATCH 1/7] added basic functions --- whatsapp-web.js/src/models/website.js | 48 ++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/whatsapp-web.js/src/models/website.js b/whatsapp-web.js/src/models/website.js index d13f47e..1d3d998 100644 --- a/whatsapp-web.js/src/models/website.js +++ b/whatsapp-web.js/src/models/website.js @@ -3,11 +3,20 @@ const {Product} = require('./product'); class Website { /** - * @param {Map} details + * @param {Object} details */ - constructor(details){ - this.details = details; - this.products = []; + constructor(companyName){ + this.firstName = ''; + this.lastName = ''; + this.companyName = companyName; + this.logoUrl = ''; + this.bannerUrl = ''; + this.desc = ''; + this.email = ''; + //uses key value pair to store product + //key is the productId of the product + //value is the product itself + this.products = {}; } /** @@ -15,9 +24,38 @@ class Website { * @param {Product} product */ addProduct(product){ - this.products.push(product); + if(this.products[product.id] == undefined) + { + this.products[product.id] = product; + return true + } + + return false; } + /** + * + * @param {string} productId + * @returns {Product} + */ + getProduct(productId){ + return this.products[productId]; + } + + /** + * + * @param {string} productId + */ + deleteProduct(productId){ + if(this.products[productId] != undefined) + { + return delete this.products[productId]; + } + + return false; + } + + } module.exports.Website = Website; \ No newline at end of file From 95dc1ae2180fcc3f3ec2ae8ad5bc0d4d126e69ec Mon Sep 17 00:00:00 2001 From: Mohammed Ashab Uddin Date: Tue, 21 Jul 2020 13:57:26 +0400 Subject: [PATCH 2/7] changed location for command.js --- whatsapp-web.js/src/models/commands.js | 10 ++++++++ .../src/userInteraction/commands.js | 23 ------------------- 2 files changed, 10 insertions(+), 23 deletions(-) create mode 100644 whatsapp-web.js/src/models/commands.js delete mode 100644 whatsapp-web.js/src/userInteraction/commands.js diff --git a/whatsapp-web.js/src/models/commands.js b/whatsapp-web.js/src/models/commands.js new file mode 100644 index 0000000..b64187c --- /dev/null +++ b/whatsapp-web.js/src/models/commands.js @@ -0,0 +1,10 @@ +class Command{ + + + constructor({command,callback}){ + this.command = command; + this.callback = callback; + } +} + +module.exports.Command = Command; diff --git a/whatsapp-web.js/src/userInteraction/commands.js b/whatsapp-web.js/src/userInteraction/commands.js deleted file mode 100644 index 01dc992..0000000 --- a/whatsapp-web.js/src/userInteraction/commands.js +++ /dev/null @@ -1,23 +0,0 @@ -class Command{ - - - constructor({command, message, callback}){ - this.command = command; - this.message = message; - this.callback = callback; - } - - getCommand(){ - return this.command; - } - - getCallback(){ - return this.callback; - } - - getMessage(){ - return this.message; - } -} - -module.exports.Command = Command; From 0efda2dc113ff706f9f774204922c54b2831463c Mon Sep 17 00:00:00 2001 From: Mohammed Ashab Uddin Date: Tue, 21 Jul 2020 13:58:04 +0400 Subject: [PATCH 3/7] added data model and user model --- whatsapp-web.js/src/models/data.js | 50 ++++++++++++++++++++++++++++++ whatsapp-web.js/src/models/user.js | 43 +++++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 whatsapp-web.js/src/models/data.js create mode 100644 whatsapp-web.js/src/models/user.js diff --git a/whatsapp-web.js/src/models/data.js b/whatsapp-web.js/src/models/data.js new file mode 100644 index 0000000..39cbd95 --- /dev/null +++ b/whatsapp-web.js/src/models/data.js @@ -0,0 +1,50 @@ +const { User } = require("../models/user"); +const { Website } = require("../models/website"); + +module.exports.data = new StructuredData(); + +class StructuredData { + + constructor() { + this.data={}; + } + + addUser(id){ + if(this.data[id] != undefined) + { + this.data[id] = new User(id); + return true + } + + return false; + } + + /** + * + * @param {number} id + * @returns {User} + */ + getUser(id){ + return this.data[id]; + } + + deleteUser(id){ + if(this.data[id] != undefined) + { + return delete this.data[id]; + + } + + return false; + } + + +} + +/* +data structured: +data = { + : , + : +} +*/ \ No newline at end of file diff --git a/whatsapp-web.js/src/models/user.js b/whatsapp-web.js/src/models/user.js new file mode 100644 index 0000000..febb440 --- /dev/null +++ b/whatsapp-web.js/src/models/user.js @@ -0,0 +1,43 @@ + +const {Website} = require('./website'); + +class User{ + + constructor(id){ + this.id = id; + //uses key value pair to store website + //key is the companyName of the website + //value is the website itself + this.websites = {}; + } + + /** + * + * @param {Website} website + */ + addWebsite(website){ + if(this.websites[website.companyName] != undefined) + { + return false; + }else{ + this.websites[website.companyName] = website; + return true; + } + } + + deleteWebsite(companyName){ + if(this.websites[companyName] != undefined) + { + return delete this.websites[companyName]; + }else{ + return false + } + } + + getWebsite(companyName){ + return this.websites[companyName]; + } + +} + +module.exports.User = User; \ No newline at end of file From d7adb17b37a267bf512cf669a3dc74c2601ca157 Mon Sep 17 00:00:00 2001 From: Mohammed Ashab Uddin Date: Tue, 21 Jul 2020 13:58:19 +0400 Subject: [PATCH 4/7] slight changes --- whatsapp-web.js/src/models/data.js | 4 +-- .../src/userInteraction/messages.js | 31 ++++++++++++------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/whatsapp-web.js/src/models/data.js b/whatsapp-web.js/src/models/data.js index 39cbd95..d792761 100644 --- a/whatsapp-web.js/src/models/data.js +++ b/whatsapp-web.js/src/models/data.js @@ -1,5 +1,5 @@ -const { User } = require("../models/user"); -const { Website } = require("../models/website"); +const { User } = require("./user"); +const { Website } = require("./website"); module.exports.data = new StructuredData(); diff --git a/whatsapp-web.js/src/userInteraction/messages.js b/whatsapp-web.js/src/userInteraction/messages.js index 1f39c14..e23b262 100644 --- a/whatsapp-web.js/src/userInteraction/messages.js +++ b/whatsapp-web.js/src/userInteraction/messages.js @@ -1,20 +1,26 @@ -const { Command } = require("./commands"); -const { onWG } = require("../businessLogic/logic"); +const { Command } = require("../models/commands"); +const logic = require("../businessLogic/logic"); /////////// //add the commands here /////////// const commands = [ - new Command({ + //User command command: 'wg', - message : [ - `stop it and get some help by using the following command *wg help*`, - `Hope everything works well` - ] , + + //function to be executed callback : () => { - onWG(); + + logic.onWG(); + //mesage to be sent to the user + let message = [ + `stop it and get some help by using the following command *wg help*`, + `Hope everything works well` + ]; + + return message; } }), @@ -22,7 +28,7 @@ const commands = [ -module.exports= onMessage = (message, client) => { +const onMessage = (message, client) => { let command = null; @@ -30,7 +36,7 @@ module.exports= onMessage = (message, client) => { if(message.body.startsWith("wg")) { for (let c of commands){ - if(c.getCommand() == message.body) + if(c.command == message.body) { command = c; break; @@ -38,8 +44,8 @@ module.exports= onMessage = (message, client) => { } if(command != null){ - command.getCallback()(); - for (let msg of command.getMessage()) + let messageToBeSent = command.callback(); + for (let msg of messageToBeSent) { client.sendMessage(message.from, msg, new Object()); } @@ -48,5 +54,6 @@ module.exports= onMessage = (message, client) => { }; +module.exports.onMessage = onMessage; //export default onMessage; \ No newline at end of file From 97e7e4ae85efaa77dbc53801128a5169f0d430c5 Mon Sep 17 00:00:00 2001 From: Mohammed Ashab Uddin Date: Tue, 21 Jul 2020 14:10:42 +0400 Subject: [PATCH 5/7] added commands.md --- whatsapp-web.js/index.js | 3 ++- whatsapp-web.js/src/businessLogic/logic.js | 16 ++++++++++++ whatsapp-web.js/src/commands.md | 29 ++++++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 whatsapp-web.js/src/commands.md diff --git a/whatsapp-web.js/index.js b/whatsapp-web.js/index.js index 518bc28..ff4f066 100644 --- a/whatsapp-web.js/index.js +++ b/whatsapp-web.js/index.js @@ -15,7 +15,6 @@ if (fs.existsSync(SESSION_FILE_PATH)) const client = new Client({ puppeteer: { headless: false }, session: sessionCfg }); client.initialize(); - client.on('qr', (qr) => { console.log('QR RECEIVED', qr); @@ -32,10 +31,12 @@ client.on('authenticated', (session) => } }); }); + client.on('auth_failure', (msg) => { console.error('AUTHENTICATION FAILURE', msg); }); + client.on('ready', () => { console.log('READY'); diff --git a/whatsapp-web.js/src/businessLogic/logic.js b/whatsapp-web.js/src/businessLogic/logic.js index e349610..483cb10 100644 --- a/whatsapp-web.js/src/businessLogic/logic.js +++ b/whatsapp-web.js/src/businessLogic/logic.js @@ -1,4 +1,20 @@ +const { Website } = require("../models/website"); +const { data } = require("../models/data"); module.exports.onWG = () => { console.log('hello world'); +} + +module.exports.onCreate = (id, companyName) => { + + //get the user + let user = data.getUser(id); + if(user == undefined) + { + data.addUser(id); + user = data.getUser(id); + } + + //add the website with the company name + user.addWebsite(new Website(companyName)); } \ No newline at end of file diff --git a/whatsapp-web.js/src/commands.md b/whatsapp-web.js/src/commands.md new file mode 100644 index 0000000..a00a847 --- /dev/null +++ b/whatsapp-web.js/src/commands.md @@ -0,0 +1,29 @@ + +# Commands available for user interaction + +*wg* -> Command wg help to get the avaialabe instructions +*wg help* -> The following are the available commands: +*wg create -> creates a framework for the website after getting details of the website + +# Following commands only works when a website is created + +*wg product all* -> shows all the products that are created +*wg product new* -> creates a new product with generated Id +*wg product * -> if the id exists, the product with “id“ is selected, else, create a new product with the id given + +# NOTE : +User should be given feedback on their commands. For example: +If a user created a product, the bot should reply, "a product has been created with the id : " +If a user created a product without a website, the bot should handle the error and reply, "A website should be selected or created before creating a product" + +# Following command only works if a product is selected +*wg product info* -> shows the information about the product. Ie name, cost, description, image +*wg product name* -> set the name of the product +*wg product cost* -> set the cost of the product +*wg product desc* -> set the description of the product +*wg product image* -> sets the image of the product. The caption of the image should be the command. +*wg finished* -> creates the website and gives a link to the website maker + + +# Note: +If you think these commands are not enough, please add them in a seperate section with a clear defination. \ No newline at end of file From aee182a02fb51297f3173d689eb96677a22fa454 Mon Sep 17 00:00:00 2001 From: Mohammed Ashab Uddin Date: Tue, 21 Jul 2020 14:18:04 +0400 Subject: [PATCH 6/7] added tasks to be completed --- whatsapp-web.js/src/tasks.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 whatsapp-web.js/src/tasks.md diff --git a/whatsapp-web.js/src/tasks.md b/whatsapp-web.js/src/tasks.md new file mode 100644 index 0000000..16a7fc9 --- /dev/null +++ b/whatsapp-web.js/src/tasks.md @@ -0,0 +1,6 @@ + +1. add the commands +2. add the logic for every commands +3. add the messages with the logic on the command callback function + + From d737615385b349010b309f1a45dd0c1f25b8da87 Mon Sep 17 00:00:00 2001 From: Mohammed Ashab Uddin Date: Tue, 21 Jul 2020 14:56:05 +0400 Subject: [PATCH 7/7] added some commands --- whatsapp-web.js/src/commands.md | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/whatsapp-web.js/src/commands.md b/whatsapp-web.js/src/commands.md index a00a847..2333c16 100644 --- a/whatsapp-web.js/src/commands.md +++ b/whatsapp-web.js/src/commands.md @@ -3,7 +3,19 @@ *wg* -> Command wg help to get the avaialabe instructions *wg help* -> The following are the available commands: -*wg create -> creates a framework for the website after getting details of the website +*wg create -> creates a website without details + +# Note: +After the user uses *wg create *. The bot should instruct the user to enter the rest of the details. +To see the details to be entered, please check *website.js* under models folder. + +The commands should follow the rules below : +*wg website firstName* +*wg website lastName* +...etc + + + # Following commands only works when a website is created @@ -24,6 +36,12 @@ If a user created a product without a website, the bot should handle the error a *wg product image* -> sets the image of the product. The caption of the image should be the command. *wg finished* -> creates the website and gives a link to the website maker +# delete +Users should be able to delete products and website +*wg delete product * +*wg delete website * + + # Note: If you think these commands are not enough, please add them in a seperate section with a clear defination. \ No newline at end of file