Created
February 25, 2018 15:31
-
-
Save VishDev12/c54ed2ba4aba0b6ffd8f9714bb82dcd2 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/movoxow
This file contains hidden or 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
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width"> | |
| <title>JS Bin</title> | |
| </head> | |
| <body> | |
| <script id="jsbin-javascript"> | |
| var restify = require("restify"); | |
| var builder = require("botbuilder"); | |
| var botbuilder_azure = require("botbuilder-azure"); | |
| // Setup Restify Server | |
| var server = restify.createServer(); | |
| server.listen(process.env.port || process.env.PORT || 3978, function() { | |
| console.log("%s listening to %s", server.name, server.url); | |
| }); | |
| // Create chat connector for communicating with the Bot Framework Service | |
| var connector = new builder.ChatConnector({ | |
| appId: process.env.MicrosoftAppId, | |
| appPassword: process.env.MicrosoftAppPassword, | |
| openIdMetadata: process.env.BotOpenIdMetadata | |
| }); | |
| // Listen for messages from users | |
| server.post("/api/messages", connector.listen()); | |
| //Table Storage adapter | |
| var tableName = "EmCue"; | |
| var storageName = "emerphone8671"; | |
| var storageKey = | |
| "WdeEemHdi5Q3+2tlqUaBZ8AyJhTTqgmOwps09ukX5/NpLReV1qNnC1+wwH4JOSuWdSy1dP+hLtIsWYBpIX5roQ=="; | |
| var azureTableClient = new botbuilder_azure.AzureTableClient( | |
| tableName, | |
| storageName, | |
| storageKey | |
| ); | |
| var tableStorage = new botbuilder_azure.AzureBotStorage( | |
| { gzipData: false }, | |
| azureTableClient | |
| ); | |
| var luisAppId = "70d27f35-0431-40a4-ab83-51697ca5740d"; | |
| var luisAPIKey = "312548959f104d08992d709576a2bdc2"; | |
| var luisAPIHostName = | |
| "https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/70d27f35-0431-40a4-ab83-51697ca5740d?subscription-key=312548959f104d08992d709576a2bdc2&spellCheck=true&bing-spell-check-subscription-key={5a79d6d8afa541f09ba5a180fe5e9ce2}&verbose=true&timezoneOffset=330&q="; | |
| // Create your bot with a function to receive messages from the user | |
| var bot = new builder.UniversalBot(connector); | |
| bot.set("storage", tableStorage); | |
| var recognizer = new builder.LuisRecognizer(luisAPIHostName); | |
| var intents = new builder.IntentDialog({ recognizers: [recognizer] }) | |
| .matches("greeting", session => { | |
| session.beginDialog("greeting"); | |
| }) | |
| .matches("unmotivated", session => { | |
| session.beginDialog("unmotivated"); | |
| }) | |
| .matches("panicAttack", session => { | |
| session.beginDialog("panicAttack"); | |
| }) | |
| .matches("good", session => { | |
| session.beginDialog("good") | |
| }); | |
| bot.dialog("/", intents); | |
| bot.dialog("good", function(session) { | |
| session.send("It's great to know you're doing well! \n Do feel free to reach out!"); | |
| session.endDialog(); | |
| }); | |
| bot.dialog("greeting", function(session) { | |
| session.send( | |
| "Hi there! I'm Narpan, your mental health assistant. How are you feeling right now?" | |
| ); | |
| session.endDialog(); | |
| }); | |
| bot.dialog("panicAttack", [ | |
| function(session) { | |
| builder.Prompts.choice(session, "Would you like some help?", [ | |
| "Yes, please!", | |
| "Not really" | |
| ]); | |
| }, | |
| function(session, results, next) { | |
| if (results.response.entity == "Yes, please!") { | |
| next(); | |
| } else { | |
| session.send("No issues. I hope you feel better soon! And as always, remember to breathe deeply."); | |
| session.endDialog(); | |
| } | |
| }, | |
| function(session) { | |
| builder.Prompts.choice( | |
| session, | |
| "Let's try a breathing exercise that I particularly like.", | |
| ["You breathe?!"] | |
| ); | |
| }, | |
| function(session) { | |
| session.sendTyping(); | |
| session.send( | |
| "You should totally visit my server farm. These kind humans spend millions to cool down my hot breath!" | |
| ); | |
| session.sendTyping(); | |
| session.send( | |
| "But anyway, that's enough about me. How about we get started?" | |
| ); | |
| session.sendTyping(); | |
| builder.Prompts.choice( | |
| session, | |
| "Find a quiet place near you where you won't be distracted easily. Let me know when you take a seat.", | |
| "I'm here!" | |
| ); | |
| }, | |
| function(session, results) { | |
| session.sendTyping(); | |
| session.send("Now, I want you to think about how you're breathing."); | |
| session.sendTyping(); | |
| session.send( | |
| "When you inhale, imagine a gentle stream of air entering your body. Now exhale, and feel the stream slowly leave your body." | |
| ); | |
| session.sendTyping(); | |
| builder.Prompts.choice( | |
| session, | |
| "I want you to count how many seconds each inhalation and exhalation takes.", | |
| "What's next?" | |
| ); | |
| }, | |
| function(session) { | |
| session.sendTyping(); | |
| session.send( | |
| "Now, as you inhale, do it for an extra second. And do the same when you exhale." | |
| ); | |
| session.sendTyping(); | |
| session.send( | |
| "Gently, remember. We don't want you huffing and puffing the big, bad wolf now, do we?" | |
| ) | |
| session.sendTyping(); | |
| builder.Prompts.choice( | |
| session, | |
| "Let me know when you've gotten used to this pace.", | |
| "I'm acing it!" | |
| ); | |
| }, | |
| function(session) { | |
| session.sendTyping(); | |
| session.send("That's great!"); | |
| session.sendTyping(); | |
| session.send( | |
| "Continue slowing your breath until you're breathing as slowly as you possibly can without turning into a hibernating bear." | |
| ); | |
| session.sendTyping(); | |
| builder.Prompts.choice( | |
| session, | |
| "It's good to do this exercise for ten minutes. Would you like me to remind you then?", | |
| ["Let's move on"] | |
| ); | |
| }, | |
| function(session) { | |
| session.send("Great! Feel free to ask me anything!") | |
| session.endDialog(); | |
| } | |
| ]); | |
| bot.dialog("unmotivated", [ | |
| function(session) { | |
| var cards = getCards(); | |
| var reply = new builder.Message(session) | |
| .attachments(cards); | |
| session.sendTyping(); | |
| session.send(reply); | |
| session.sendTyping(); | |
| session.send("^How pointless, right? As if a single video will make things better. If you ask me, the guy who made me kinda rushed it.") | |
| session.sendTyping(); | |
| session.send("Now, what else is bothering you?"); | |
| session.endDialog(); | |
| } | |
| ]); | |
| function getCards(session) { | |
| return [ | |
| new builder.VideoCard(session) | |
| .media([ | |
| { | |
| url: | |
| "https://emerphone8671.blob.core.windows.net/emcue/One%20of%20the%20BEST%20Motivational%20Videos%20Ive%20ever%20seen!.mp4" | |
| } | |
| ]) | |
| .title("Here's something to motivate you") | |
| .shareable(true), | |
| ]; | |
| } | |
| </script> | |
| <script id="jsbin-source-javascript" type="text/javascript">var restify = require("restify"); | |
| var builder = require("botbuilder"); | |
| var botbuilder_azure = require("botbuilder-azure"); | |
| // Setup Restify Server | |
| var server = restify.createServer(); | |
| server.listen(process.env.port || process.env.PORT || 3978, function() { | |
| console.log("%s listening to %s", server.name, server.url); | |
| }); | |
| // Create chat connector for communicating with the Bot Framework Service | |
| var connector = new builder.ChatConnector({ | |
| appId: process.env.MicrosoftAppId, | |
| appPassword: process.env.MicrosoftAppPassword, | |
| openIdMetadata: process.env.BotOpenIdMetadata | |
| }); | |
| // Listen for messages from users | |
| server.post("/api/messages", connector.listen()); | |
| //Table Storage adapter | |
| var tableName = "EmCue"; | |
| var storageName = "emerphone8671"; | |
| var storageKey = | |
| "WdeEemHdi5Q3+2tlqUaBZ8AyJhTTqgmOwps09ukX5/NpLReV1qNnC1+wwH4JOSuWdSy1dP+hLtIsWYBpIX5roQ=="; | |
| var azureTableClient = new botbuilder_azure.AzureTableClient( | |
| tableName, | |
| storageName, | |
| storageKey | |
| ); | |
| var tableStorage = new botbuilder_azure.AzureBotStorage( | |
| { gzipData: false }, | |
| azureTableClient | |
| ); | |
| var luisAppId = "70d27f35-0431-40a4-ab83-51697ca5740d"; | |
| var luisAPIKey = "312548959f104d08992d709576a2bdc2"; | |
| var luisAPIHostName = | |
| "https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/70d27f35-0431-40a4-ab83-51697ca5740d?subscription-key=312548959f104d08992d709576a2bdc2&spellCheck=true&bing-spell-check-subscription-key={5a79d6d8afa541f09ba5a180fe5e9ce2}&verbose=true&timezoneOffset=330&q="; | |
| // Create your bot with a function to receive messages from the user | |
| var bot = new builder.UniversalBot(connector); | |
| bot.set("storage", tableStorage); | |
| var recognizer = new builder.LuisRecognizer(luisAPIHostName); | |
| var intents = new builder.IntentDialog({ recognizers: [recognizer] }) | |
| .matches("greeting", session => { | |
| session.beginDialog("greeting"); | |
| }) | |
| .matches("unmotivated", session => { | |
| session.beginDialog("unmotivated"); | |
| }) | |
| .matches("panicAttack", session => { | |
| session.beginDialog("panicAttack"); | |
| }) | |
| .matches("good", session => { | |
| session.beginDialog("good") | |
| }); | |
| bot.dialog("/", intents); | |
| bot.dialog("good", function(session) { | |
| session.send("It's great to know you're doing well! \n Do feel free to reach out!"); | |
| session.endDialog(); | |
| }); | |
| bot.dialog("greeting", function(session) { | |
| session.send( | |
| "Hi there! I'm Narpan, your mental health assistant. How are you feeling right now?" | |
| ); | |
| session.endDialog(); | |
| }); | |
| bot.dialog("panicAttack", [ | |
| function(session) { | |
| builder.Prompts.choice(session, "Would you like some help?", [ | |
| "Yes, please!", | |
| "Not really" | |
| ]); | |
| }, | |
| function(session, results, next) { | |
| if (results.response.entity == "Yes, please!") { | |
| next(); | |
| } else { | |
| session.send("No issues. I hope you feel better soon! And as always, remember to breathe deeply."); | |
| session.endDialog(); | |
| } | |
| }, | |
| function(session) { | |
| builder.Prompts.choice( | |
| session, | |
| "Let's try a breathing exercise that I particularly like.", | |
| ["You breathe?!"] | |
| ); | |
| }, | |
| function(session) { | |
| session.sendTyping(); | |
| session.send( | |
| "You should totally visit my server farm. These kind humans spend millions to cool down my hot breath!" | |
| ); | |
| session.sendTyping(); | |
| session.send( | |
| "But anyway, that's enough about me. How about we get started?" | |
| ); | |
| session.sendTyping(); | |
| builder.Prompts.choice( | |
| session, | |
| "Find a quiet place near you where you won't be distracted easily. Let me know when you take a seat.", | |
| "I'm here!" | |
| ); | |
| }, | |
| function(session, results) { | |
| session.sendTyping(); | |
| session.send("Now, I want you to think about how you're breathing."); | |
| session.sendTyping(); | |
| session.send( | |
| "When you inhale, imagine a gentle stream of air entering your body. Now exhale, and feel the stream slowly leave your body." | |
| ); | |
| session.sendTyping(); | |
| builder.Prompts.choice( | |
| session, | |
| "I want you to count how many seconds each inhalation and exhalation takes.", | |
| "What's next?" | |
| ); | |
| }, | |
| function(session) { | |
| session.sendTyping(); | |
| session.send( | |
| "Now, as you inhale, do it for an extra second. And do the same when you exhale." | |
| ); | |
| session.sendTyping(); | |
| session.send( | |
| "Gently, remember. We don't want you huffing and puffing the big, bad wolf now, do we?" | |
| ) | |
| session.sendTyping(); | |
| builder.Prompts.choice( | |
| session, | |
| "Let me know when you've gotten used to this pace.", | |
| "I'm acing it!" | |
| ); | |
| }, | |
| function(session) { | |
| session.sendTyping(); | |
| session.send("That's great!"); | |
| session.sendTyping(); | |
| session.send( | |
| "Continue slowing your breath until you're breathing as slowly as you possibly can without turning into a hibernating bear." | |
| ); | |
| session.sendTyping(); | |
| builder.Prompts.choice( | |
| session, | |
| "It's good to do this exercise for ten minutes. Would you like me to remind you then?", | |
| ["Let's move on"] | |
| ); | |
| }, | |
| function(session) { | |
| session.send("Great! Feel free to ask me anything!") | |
| session.endDialog(); | |
| } | |
| ]); | |
| bot.dialog("unmotivated", [ | |
| function(session) { | |
| var cards = getCards(); | |
| var reply = new builder.Message(session) | |
| .attachments(cards); | |
| session.sendTyping(); | |
| session.send(reply); | |
| session.sendTyping(); | |
| session.send("^How pointless, right? As if a single video will make things better. If you ask me, the guy who made me kinda rushed it.") | |
| session.sendTyping(); | |
| session.send("Now, what else is bothering you?"); | |
| session.endDialog(); | |
| } | |
| ]); | |
| function getCards(session) { | |
| return [ | |
| new builder.VideoCard(session) | |
| .media([ | |
| { | |
| url: | |
| "https://emerphone8671.blob.core.windows.net/emcue/One%20of%20the%20BEST%20Motivational%20Videos%20Ive%20ever%20seen!.mp4" | |
| } | |
| ]) | |
| .title("Here's something to motivate you") | |
| .shareable(true), | |
| ]; | |
| } | |
| </script></body> | |
| </html> |
This file contains hidden or 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
| var restify = require("restify"); | |
| var builder = require("botbuilder"); | |
| var botbuilder_azure = require("botbuilder-azure"); | |
| // Setup Restify Server | |
| var server = restify.createServer(); | |
| server.listen(process.env.port || process.env.PORT || 3978, function() { | |
| console.log("%s listening to %s", server.name, server.url); | |
| }); | |
| // Create chat connector for communicating with the Bot Framework Service | |
| var connector = new builder.ChatConnector({ | |
| appId: process.env.MicrosoftAppId, | |
| appPassword: process.env.MicrosoftAppPassword, | |
| openIdMetadata: process.env.BotOpenIdMetadata | |
| }); | |
| // Listen for messages from users | |
| server.post("/api/messages", connector.listen()); | |
| //Table Storage adapter | |
| var tableName = "EmCue"; | |
| var storageName = "emerphone8671"; | |
| var storageKey = | |
| "WdeEemHdi5Q3+2tlqUaBZ8AyJhTTqgmOwps09ukX5/NpLReV1qNnC1+wwH4JOSuWdSy1dP+hLtIsWYBpIX5roQ=="; | |
| var azureTableClient = new botbuilder_azure.AzureTableClient( | |
| tableName, | |
| storageName, | |
| storageKey | |
| ); | |
| var tableStorage = new botbuilder_azure.AzureBotStorage( | |
| { gzipData: false }, | |
| azureTableClient | |
| ); | |
| var luisAppId = "70d27f35-0431-40a4-ab83-51697ca5740d"; | |
| var luisAPIKey = "312548959f104d08992d709576a2bdc2"; | |
| var luisAPIHostName = | |
| "https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/70d27f35-0431-40a4-ab83-51697ca5740d?subscription-key=312548959f104d08992d709576a2bdc2&spellCheck=true&bing-spell-check-subscription-key={5a79d6d8afa541f09ba5a180fe5e9ce2}&verbose=true&timezoneOffset=330&q="; | |
| // Create your bot with a function to receive messages from the user | |
| var bot = new builder.UniversalBot(connector); | |
| bot.set("storage", tableStorage); | |
| var recognizer = new builder.LuisRecognizer(luisAPIHostName); | |
| var intents = new builder.IntentDialog({ recognizers: [recognizer] }) | |
| .matches("greeting", session => { | |
| session.beginDialog("greeting"); | |
| }) | |
| .matches("unmotivated", session => { | |
| session.beginDialog("unmotivated"); | |
| }) | |
| .matches("panicAttack", session => { | |
| session.beginDialog("panicAttack"); | |
| }) | |
| .matches("good", session => { | |
| session.beginDialog("good") | |
| }); | |
| bot.dialog("/", intents); | |
| bot.dialog("good", function(session) { | |
| session.send("It's great to know you're doing well! \n Do feel free to reach out!"); | |
| session.endDialog(); | |
| }); | |
| bot.dialog("greeting", function(session) { | |
| session.send( | |
| "Hi there! I'm Narpan, your mental health assistant. How are you feeling right now?" | |
| ); | |
| session.endDialog(); | |
| }); | |
| bot.dialog("panicAttack", [ | |
| function(session) { | |
| builder.Prompts.choice(session, "Would you like some help?", [ | |
| "Yes, please!", | |
| "Not really" | |
| ]); | |
| }, | |
| function(session, results, next) { | |
| if (results.response.entity == "Yes, please!") { | |
| next(); | |
| } else { | |
| session.send("No issues. I hope you feel better soon! And as always, remember to breathe deeply."); | |
| session.endDialog(); | |
| } | |
| }, | |
| function(session) { | |
| builder.Prompts.choice( | |
| session, | |
| "Let's try a breathing exercise that I particularly like.", | |
| ["You breathe?!"] | |
| ); | |
| }, | |
| function(session) { | |
| session.sendTyping(); | |
| session.send( | |
| "You should totally visit my server farm. These kind humans spend millions to cool down my hot breath!" | |
| ); | |
| session.sendTyping(); | |
| session.send( | |
| "But anyway, that's enough about me. How about we get started?" | |
| ); | |
| session.sendTyping(); | |
| builder.Prompts.choice( | |
| session, | |
| "Find a quiet place near you where you won't be distracted easily. Let me know when you take a seat.", | |
| "I'm here!" | |
| ); | |
| }, | |
| function(session, results) { | |
| session.sendTyping(); | |
| session.send("Now, I want you to think about how you're breathing."); | |
| session.sendTyping(); | |
| session.send( | |
| "When you inhale, imagine a gentle stream of air entering your body. Now exhale, and feel the stream slowly leave your body." | |
| ); | |
| session.sendTyping(); | |
| builder.Prompts.choice( | |
| session, | |
| "I want you to count how many seconds each inhalation and exhalation takes.", | |
| "What's next?" | |
| ); | |
| }, | |
| function(session) { | |
| session.sendTyping(); | |
| session.send( | |
| "Now, as you inhale, do it for an extra second. And do the same when you exhale." | |
| ); | |
| session.sendTyping(); | |
| session.send( | |
| "Gently, remember. We don't want you huffing and puffing the big, bad wolf now, do we?" | |
| ) | |
| session.sendTyping(); | |
| builder.Prompts.choice( | |
| session, | |
| "Let me know when you've gotten used to this pace.", | |
| "I'm acing it!" | |
| ); | |
| }, | |
| function(session) { | |
| session.sendTyping(); | |
| session.send("That's great!"); | |
| session.sendTyping(); | |
| session.send( | |
| "Continue slowing your breath until you're breathing as slowly as you possibly can without turning into a hibernating bear." | |
| ); | |
| session.sendTyping(); | |
| builder.Prompts.choice( | |
| session, | |
| "It's good to do this exercise for ten minutes. Would you like me to remind you then?", | |
| ["Let's move on"] | |
| ); | |
| }, | |
| function(session) { | |
| session.send("Great! Feel free to ask me anything!") | |
| session.endDialog(); | |
| } | |
| ]); | |
| bot.dialog("unmotivated", [ | |
| function(session) { | |
| var cards = getCards(); | |
| var reply = new builder.Message(session) | |
| .attachments(cards); | |
| session.sendTyping(); | |
| session.send(reply); | |
| session.sendTyping(); | |
| session.send("^How pointless, right? As if a single video will make things better. If you ask me, the guy who made me kinda rushed it.") | |
| session.sendTyping(); | |
| session.send("Now, what else is bothering you?"); | |
| session.endDialog(); | |
| } | |
| ]); | |
| function getCards(session) { | |
| return [ | |
| new builder.VideoCard(session) | |
| .media([ | |
| { | |
| url: | |
| "https://emerphone8671.blob.core.windows.net/emcue/One%20of%20the%20BEST%20Motivational%20Videos%20Ive%20ever%20seen!.mp4" | |
| } | |
| ]) | |
| .title("Here's something to motivate you") | |
| .shareable(true), | |
| ]; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment