Skip to content

Commit

Permalink
Merge pull request #268 from nikhilmaske-2001/noMatch
Browse files Browse the repository at this point in the history
Cover the case of noMatch in processMessages. Fixes #257
  • Loading branch information
vasani-arpit authored Oct 21, 2021
2 parents e309322 + 481be3d commit 8914ed8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wbot",
"version": "0.21.0",
"version": "0.22.0",
"description": "A simple whatsapp reply bot using puppeteer.",
"main": "src/index.js",
"scripts": {
Expand Down
12 changes: 7 additions & 5 deletions src/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,11 @@ async function processMessages(data) {
if (exactMatch != undefined) {
response = await resolveSpintax(exactMatch.response);
window.log(`Replying with ${response}`);
} else {
response = await resolveSpintax(intents.noMatch);
window.log(`No exact match found. So replying with ${response} instead`);
}
var PartialMatch = intents.bot.find(obj => obj.contains.find(ex => message.body.toLowerCase().search(ex) > -1));
if (PartialMatch != undefined) {
response = await resolveSpintax(PartialMatch.response);
window.log(`Replying with ${response}`);
} else {
console.log("No partial match found");
}
WAPI.sendSeen(message.chatId._serialized);
response = response.fillVariables({ name: message.sender.pushname, phoneNumber: message.sender.id.user, greetings: greetings() })
Expand Down Expand Up @@ -200,6 +195,13 @@ async function processMessages(data) {
window.log("Processing webhook from block")
processWebhook((exactMatch || PartialMatch).webhook, message, body)
}
} else {
// We are sure we haven't found any exact or partial match
// as we are already checking it in the above if statement
// So process with the noMatch logic only
response = await resolveSpintax(intents.noMatch);
window.log(`No exact or partial match found. So replying with ${response} instead`);
WAPI.sendMessage2(message.chatId._serialized, response);
}
}
}
Expand Down

0 comments on commit 8914ed8

Please sign in to comment.