Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Code
- Loading branch information
Leonas112
authored and
Leonas112
committed
Apr 6, 2021
0 parents
commit 0d73fc3a24e55f8d720131e2bc2179b47fd11b94
Showing
26 changed files
with
4,569 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.env | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
// __ __ ___ ___ | ||
// |__) / \ | |__/ | | | ||
// |__) \__/ | | \ | | | ||
|
||
// This is the main file for the HelperBot bot. | ||
|
||
// Import Botkit's core features | ||
const { Botkit, BotkitConversation } = require('botkit'); | ||
const { BotkitCMSHelper } = require('botkit-plugin-cms'); | ||
|
||
// Import a platform-specific adapter for web. | ||
|
||
const { WebAdapter } = require('botbuilder-adapter-web'); | ||
|
||
const { MongoDbStorage } = require('botbuilder-storage-mongodb'); | ||
|
||
|
||
// Load process.env values from .env file | ||
require('dotenv').config(); | ||
|
||
let storage = null; | ||
if (process.env.MONGO_URI) { | ||
storage = mongoStorage = new MongoDbStorage({ | ||
url : process.env.MONGO_URI, | ||
}); | ||
} | ||
|
||
|
||
const adapter = new WebAdapter({}); | ||
|
||
|
||
const controller = new Botkit({ | ||
webhook_uri: '/api/messages', | ||
|
||
adapter: adapter, | ||
|
||
storage | ||
}); | ||
|
||
if (process.env.CMS_URI) { | ||
controller.usePlugin(new BotkitCMSHelper({ | ||
uri: process.env.CMS_URI, | ||
token: process.env.CMS_TOKEN, | ||
})); | ||
} | ||
|
||
// Once the bot has booted up its internal services, you can use them to do stuff. | ||
controller.ready(() => { | ||
|
||
|
||
|
||
// load traditional developer-created local custom feature modules | ||
controller.loadModules(__dirname + '/features'); | ||
|
||
|
||
|
||
const MAIN_DIALOG_ID = 'conversation'; | ||
|
||
let convo = new BotkitConversation(MAIN_DIALOG_ID, controller); | ||
|
||
|
||
let greet = ['hello', 'hi', 'good afternoon', 'good morning', 'good evening', 'howdy']; | ||
let services = [ | ||
'1. Car spare parts.', | ||
'2. Car wheels and tires.', | ||
'3. Service.', | ||
'4. Looking for a new car.', | ||
'5. Loking for a used car.', | ||
'6. Car making weird noises? Need advice while repairing your car?.', | ||
'7. Issues with services provided by us.' ]; | ||
|
||
function convertoToString(array){ | ||
|
||
sentence = "" | ||
array.forEach(element => sentence += (element + "\n")); | ||
console.log(sentence); | ||
return sentence; | ||
} | ||
|
||
|
||
controller.hears(greet, 'message', async (bot, message) => { | ||
await bot.beginDialog(MAIN_DIALOG_ID, 'conversation') | ||
}); | ||
|
||
|
||
|
||
convo.say('Hello'); | ||
convo.say('I am Angus , please enter a number depending on the services you would like our dealership to provide ') | ||
|
||
|
||
convo.ask(convertoToString(services),[ | ||
{ | ||
pattern: '1', | ||
handler: async function (response, convo, bot) { | ||
return await convo.say('For spare parts please visit our website : www.clientswebsite.com/spareparts . Or contact our warehouse manager for a more specific querries : +441234569'); | ||
|
||
}, | ||
}, | ||
{ | ||
pattern: '2', | ||
handler: async function (response, convo, bot) { | ||
await convo.say('If you are looking for new wheels I suggest to check our website link : www.clientswebsite.com/wheelsandtires . But if you are looking for wheel balancing or fitment services or similar please contact our service manager, he will be able to answer all your questions : +44789456123'); | ||
}, | ||
}, | ||
{ | ||
pattern: '3', | ||
handler: async function (response, convo, bot) { | ||
await convo.say('Need to service your car? Or you would like to check how is the repair of your car going contact us : +44789456123'); | ||
}, | ||
}, | ||
{ | ||
pattern: '4', | ||
handler: async function (response, convo, bot) { | ||
await convo.say('Our dealership offers a variety of new cars differrent models and an opportunity to order a custom made car of your choice, for more detailed information please visit our website: www.clientswebsite.com/wheelsandtires . Or call our sales management team : +44781236945'); | ||
}, | ||
}, | ||
{ | ||
pattern: '5', | ||
handler: async function (response, convo, bot) { | ||
await convo.say('We help people sell the cars they dont use anymore please visit our website : www.clientswebsite.com/usedcars'); | ||
}, | ||
}, | ||
{ | ||
pattern: '6', | ||
handler: async function (response, convo, bot) { | ||
await convo.say('Our team has extensive knowledge of car repair and we will gladly give you an advice when it comes to car questions our contact number is : +44123058744'); | ||
}, | ||
}, | ||
{ | ||
pattern: '7', | ||
handler: async function (response, convo, bot) { | ||
await convo.say('I am sorry to hear that, here is the contact information call us we will gladly sort the issue out! : +44123456789'); | ||
}, | ||
|
||
}, | ||
|
||
|
||
]); | ||
|
||
|
||
controller.addDialog(convo); | ||
|
||
|
||
|
||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. | ||
*/ | ||
const express = require('express'); | ||
const path = require('path'); | ||
|
||
module.exports = function(controller) { | ||
|
||
// make public/index.html available as localhost/index.html | ||
// by making the /public folder a static/public asset | ||
controller.publicFolder('/', path.join(__dirname,'..','public')); | ||
|
||
console.log('Chat with me: http://localhost:' + (process.env.PORT || 3000)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. | ||
*/ | ||
|
||
module.exports = function(controller) { | ||
|
||
controller.hears('sample','message,direct_message', async(bot, message) => { | ||
await bot.reply(message, 'I heard a sample message.'); | ||
}); | ||
|
||
controller.on('message,direct_message', async(bot, message) => { | ||
await bot.reply(message, `Echo: ${ message.text }`); | ||
}); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. | ||
*/ | ||
module.exports = function(controller) { | ||
|
||
// use a function to match a condition in the message | ||
controller.hears(async (message) => message.text && message.text.toLowerCase() === 'foo', ['message'], async (bot, message) => { | ||
await bot.reply(message, 'I heard "foo" via a function test'); | ||
}); | ||
|
||
// use a regular expression to match the text of the message | ||
controller.hears(new RegExp(/^\d+$/), ['message','direct_message'], async function(bot, message) { | ||
await bot.reply(message,{ text: 'I heard a number using a regular expression.' }); | ||
}); | ||
|
||
// match any one of set of mixed patterns like a string, a regular expression | ||
controller.hears(['allcaps', new RegExp(/^[A-Z\s]+$/)], ['message','direct_message'], async function(bot, message) { | ||
await bot.reply(message,{ text: 'I HEARD ALL CAPS!' }); | ||
}); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* This module demonstrates the use of the typing indicator in a conversation, and when using bot.reply | ||
* Tell your bot "typing dialog" or "typing reply" to see this in action. | ||
*/ | ||
const { BotkitConversation } = require("botkit"); | ||
|
||
module.exports = function(controller) { | ||
|
||
let typing = new BotkitConversation('typing', controller); | ||
|
||
typing.say('I am going to type for a while now...'); | ||
typing.addAction('typing'); | ||
|
||
// start the typing indicator | ||
typing.addMessage({type: 'typing'}, 'typing'); | ||
// trigger a gotoThread, which gives us an opportunity to delay the next message | ||
typing.addAction('next_thread','typing'); | ||
|
||
typing.addMessage('typed!','next_thread'); | ||
|
||
// use the before handler to delay the next message | ||
typing.before('next_thread', async () => { | ||
return new Promise((resolve) => { | ||
// simulate some long running process | ||
setTimeout(resolve, 3000); | ||
}); | ||
}); | ||
|
||
controller.addDialog(typing); | ||
|
||
controller.hears('typing dialog', 'message', async (bot, message) => { | ||
await bot.beginDialog('typing'); | ||
}); | ||
|
||
controller.hears('typing reply', 'message', async (bot, message) => { | ||
|
||
await bot.reply(message, {type: 'typing'}); | ||
setTimeout(async () => { | ||
// will have to reset context because turn has now ended. | ||
await bot.changeContext(message.reference); | ||
await bot.reply(message, 'Typed!'); | ||
}, 1000); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. | ||
*/ | ||
module.exports = function(controller) { | ||
|
||
if (controller.adapter.name === 'Web Adapter') { | ||
|
||
console.log('Loading sample web features...'); | ||
|
||
controller.hears(new RegExp('quick'), 'message', async (bot, message) => { | ||
|
||
await bot.reply(message,{ | ||
text: 'Here are some quick replies', | ||
quick_replies: [ | ||
{ | ||
title: 'Foo', | ||
payload: 'foo', | ||
}, | ||
{ | ||
title: 'Bar', | ||
payload: 'bar', | ||
} | ||
] | ||
}); | ||
}); | ||
|
||
|
||
} | ||
|
||
} |
Oops, something went wrong.