Bug fixes
This commit is contained in:
Родитель
cd3d351894
Коммит
039f5c5fce
|
@ -0,0 +1,57 @@
|
|||
# Echo Bot template
|
||||
|
||||
This sample shows how to create a simple echo bot with state. The bot maintains a simple counter that increases with each message from the user. This bot example uses [`restify`](https://www.npmjs.com/package/restify).
|
||||
|
||||
# Prerequisite to run this bot locally
|
||||
- Download the bot code from the Build blade in the Azure Portal
|
||||
- Create a file called .env in the root of the project and add the botFilePath and botFileSecret to it
|
||||
- You can find the botFilePath and botFileSecret in the Azure App Service application settings
|
||||
- Your .env file should look like this
|
||||
```bash
|
||||
botFilePath=<copy value from App settings>
|
||||
botFileSecret=<copy value from App settings>
|
||||
```
|
||||
|
||||
- Run `npm install` in the root of the bot project
|
||||
- Finally run `npm start`
|
||||
|
||||
|
||||
## Testing the bot using Bot Framework Emulator
|
||||
[Microsoft Bot Framework Emulator](https://github.com/microsoft/botframework-emulator) is a desktop application that allows bot developers to test and debug their bots on localhost or running remotely through a tunnel.
|
||||
|
||||
- Install the Bot Framework Emulator from [here](https://aka.ms/botframework-emulator)
|
||||
|
||||
### Connect to bot using Bot Framework Emulator v4
|
||||
- Launch the Bot Framework Emulator
|
||||
- File -> Open bot and navigate to the bot project folder
|
||||
- Select `<your-bot-name>.bot` file
|
||||
|
||||
# Bot state
|
||||
A key to good bot design is to track the context of a conversation, so that your bot remembers things like the answers to previous questions. Depending on what your bot is used for, you may even need to keep track of conversation state or store user related information for longer than the lifetime of one given conversation.
|
||||
|
||||
In this example, the bot's state is used to track number of messages.
|
||||
|
||||
A bot's state is information it remembers in order to respond appropriately to incoming messages. The Bot Builder SDK provides classes for [storing and retrieving state data](https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-howto-v4-state?view=azure-bot-service-4.0&tabs=js) as an object associated with a user or a conversation.
|
||||
|
||||
- Conversation properties help your bot keep track of the current conversation the bot is having with the user. If your bot needs to complete a sequence of steps or switch between conversation topics, you can use conversation properties to manage steps in a sequence or track the current topic. Since conversation properties reflect the state of the current conversation, you typically clear them at the end of a session, when the bot receives an end of conversation activity.
|
||||
|
||||
- User properties can be used for many purposes, such as determining where the user's prior conversation left off or simply greeting a returning user by name. If you store a user's preferences, you can use that information to customize the conversation the next time you chat. For example, you might alert the user to a news article about a topic that interests her, or alert a user when an appointment becomes available. You should clear them if the bot receives a delete user data activity.
|
||||
|
||||
# Deploy this bot to Azure
|
||||
You can use the [MSBot](https://github.com/microsoft/botbuilder-tools) Bot Builder CLI tool to clone and configure any services this sample depends on.
|
||||
|
||||
To install all Bot Builder tools -
|
||||
```bash
|
||||
npm i -g msbot chatdown ludown qnamaker luis-apis botdispatch luisgen
|
||||
```
|
||||
|
||||
To clone this bot, run
|
||||
```
|
||||
msbot clone services -f deploymentScripts/msbotClone -n <BOT-NAME> -l <Azure-location> --subscriptionId <Azure-subscription-id>
|
||||
```
|
||||
|
||||
# Further reading
|
||||
- [Azure Bot Service Introduction](https://docs.microsoft.com/en-us/azure/bot-service/bot-service-overview-introduction?view=azure-bot-service-4.0)
|
||||
- [Bot State](https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-storage-concept?view=azure-bot-service-4.0)
|
||||
- [Write directly to storage](https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-howto-v4-storage?view=azure-bot-service-4.0&tabs=jsechoproperty%2Ccsetagoverwrite%2Ccsetag)
|
||||
- [Managing conversation and user state](https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-howto-v4-state?view=azure-bot-service-4.0&tabs=js)
|
|
@ -231,6 +231,10 @@ class MoodleWsBot {
|
|||
const userLanguage = await this.languagePreferenceProperty.get(step.context, DEFAULT_LANGUAGE);
|
||||
// If the user is authenticated the bot can use the token to make API calls.
|
||||
if (tokenResponse !== undefined) {
|
||||
if(step.context.activity.name == "signin/verifyState"){
|
||||
const state = this.conversationState.get(step.context);
|
||||
step.context.activity.text = state.commandState;
|
||||
}
|
||||
let topIntent = false;
|
||||
let results = null;
|
||||
try{
|
||||
|
|
|
@ -21,7 +21,8 @@
|
|||
"promise-retry" : "1.1.1",
|
||||
"request": "^2.88.0",
|
||||
"request-promise": "^4.2.2",
|
||||
"restify": "^6.3.4"
|
||||
"restify": "^6.3.4",
|
||||
"jsonwebtoken": "8.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^5.6.1",
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
let moodleClient = require("moodle-client");
|
||||
let rp = require("request-promise");
|
||||
let promiseRetry = require("promise-retry");
|
||||
|
||||
let jwt = require("jsonwebtoken");
|
||||
|
||||
/**
|
||||
* This class is a wrapper for the Moodle webservices.
|
||||
|
@ -20,6 +20,10 @@ class SimpleMoodleClient {
|
|||
if (!token || !token.trim()) {
|
||||
throw new Error('MoodleClient: Invalid token received.');
|
||||
}
|
||||
if(!process.env.sharedMoodleSecret || !process.env.sharedMoodleSecret.trim()){
|
||||
throw new Error('MoodleClient: Shared secret not set.');
|
||||
}
|
||||
var sharedtoken = jwt.sign({ token: token, url: url }, process.env.sharedMoodleSecret);
|
||||
let options = {
|
||||
uri: `${ url }/local/o365/token.php`,
|
||||
qs: {
|
||||
|
@ -27,7 +31,7 @@ class SimpleMoodleClient {
|
|||
'service': 'o365_webservices',
|
||||
},
|
||||
headers: {
|
||||
'Authorization': 'Bearer '+ token
|
||||
'Authorization': 'Bearer '+ sharedtoken
|
||||
},
|
||||
json: true
|
||||
};
|
||||
|
|
Загрузка…
Ссылка в новой задаче