32e8246c7d | ||
---|---|---|
.. | ||
cards | ||
data | ||
services | ||
.env sample | ||
.gitignore | ||
README.md | ||
botActivityHandler.js | ||
index.js | ||
package-lock.json | ||
package.json |
README.md
Tailwind Traders Bot Setup and Configuration
Bots allow users to interact with your web service through text, interactive cards, and task modules. Messaging extensions allow users to interact with your web service through buttons and forms in the Microsoft Teams client. They can search, or initiate actions, in an external system from the compose message area, the command box, or directly from a message.
Prerequisites
- NodeJS
- ngrok or equivalent tunneling solution
- M365 developer account or access to a Teams account with the appropriate permissions to install an app
- Microsoft Azure subscription
Setup
1. Configure Cognitive Services
Rename .env sample
file as .env
.
Import LUIS model (Language Understanding Intelligent Service)
-
Go to LUIS Portal and select
Login / Sign up
. Sign in with your account that has Microsoft Azure subscription. -
Select the arrow on the right side of the
New app
button and chooseImport as JSON
to import'TailwindLuis.json'
file available under services > CognitiveServices folder. -
Train your LUIS model by choosing
Train
on the top right. -
Test your LUIS model by choosing
Test
and try using the following uttarances as an example, "Hi", "Can you help?" and "Get me my customer list" to see the intent results. -
Publish your LUIS model by selecting
Publish
. SelectProduction slot
andDone
. -
Go to Manage on the top right and then Azure resources tab. Select
Add prediction resource
and chooseCreate a new prediction resource
link on the bottom. Fill the fields as the following and clickDone
:- Azure subscription: Choose your Azure subscription
- Azure resource group: Choose a resource group
- Location: Choose preferred location
- Price Tier: Choose preferred price tier
-
Copy
Endpoint URL
andPrimary Key
from Prediction Resources under the Azure Resources. Also, copyApp ID
from Application Settings under the Settings tab. Add the following fields in.env
file:LuisAppId= <App-ID> LuisAPIKey= <Primary-Key> LuisAPIHostName= <Endpoint-URL>
Create QnA knowledge base
-
Go to QnA Maker Portal and select
Sign in
from top right. Sign in with your account that has Azure subscription. -
Click on
Create a knowledge base
on the top and complete the steps as follows:-
STEP 1: Select
Create a QnA Service
, you will be directed to Azure Portal and login with the same account. Fill the fields as follows and selectReview + create
, thenCreate
:- Subscription: Choose your Azure Subscription
- Resource group: Choose a resource group or create new
- Name: Give a name to your QnA service
- Price tier: Choose pricing tier as Standard
- Azure Search location: Choose preferred location
- Azure Search pricing tier: Choose pricing tier as Standard
- App name: Gıve a name to your app
- Website location: Choose preffered location
- App insights: Enable
- App insights location: Choose preferred location
Once your QnA service is created, return to QnA Maker Portal and continue with the steps.
-
STEP 2: Select
Refresh
and choose the fields as following:- Microsoft Azure Directory ID: Choose your tenant
- Azure subscription name: Choose your Azure subscription
- Azure QnA service: Choose your QnA service you recently created
- Language: English
-
STEP 3: Give a name to your knowledge base
-
STEP 4: Populate your knowledge base by selecting
+ Add file
link and chooseTailwindQnAMaker.csv
file available under theservices > CognitiveServices
folder. Keep Chit-chat asNone
. -
Step 5: Select
Create your KB
.
-
-
Select
Save and train
from the top right. -
Click on
Test
and test your knowledge base by asking questions as the following examples: "How old are you?", "Do you breathe?", "Can you dream?". -
Go to PUBLISH and select
Publish
to publish your knowledge base. -
Under the Postman title, copy your
KnowledgeBase-ID
from /knowledgebases/xxxx-xxxxx-xxxx
/generateAnswer, also copyHost
andAuthorization: EndpointKey
. Add the following fields in.env
file:QnAKnowledgebaseId= <KnowledgeBase-ID> QnAEndpointKey= <Authorization: EndpointKey> QnAEndpointHostName= <Host>
2. Configure Ngrok
Your app will run from a localhost server. You will need to setup Ngrok in order to tunnel from the Teams client to localhost.
Install Ngrok
Go to Ngrok website and install ngrok.
Run Ngrok
-
Unzip and open ngrok, then run the following script:
ngrok http -host-header=rewrite 3978
-
Copy your
https://{subdomain}.ngrok.io
, you will need it in the next step.
3. Create Azure Bot Channels Registration
-
Go to Azure Portal and select
+ Create a resource
. Search forBot Channels Registration
and chooseCreate
. Fill the fields as follows and selectCreate
:- Bot handle: Give a unique name to your bot
- Subscription: Choose your subscription
- Resource group: Choose a resource group or create new
- Location: Choose preferred location
- Pricing tier: Choose preferred pricing tier
- Messaging endpoint: For the Messaging endpoint URL, use the current
https
URL you were given by running ngrok and append it with the path/api/messages
. It should like something workhttps://{subdomain}.ngrok.io/api/messages
. - Application Insights: On
- Application Insights Location: Choose preferred location
- Microsoft App ID and password: Auto create App ID and password
-
Go to your Bot Channels Registration resource and select
Channel
from left-hand side menu. ChooseMicrosoft Teams
icon to enable Teams as a channel andSave
. -
Go to Settings from left-hand side menu and find
Microsoft App ID
and click onManage
link on the right. You will be directed to Certificates & secrets. -
In Certificates & secrets, select
+ New client secret
andAdd
. Copy yourClient Secret Value
. -
Go to Overview, and copy
Application (Client) ID
. -
Add the following fields in
.env
file:BotId= <Application-(Client)-ID> BotPassword= <Client-Secret-Value>
4. Build and run
Open your terminal in Visual Studio Code (Ctrl+ Shift + '
) and type the following scripts in sequence:
-
Go to your Teams bot project folder:
cd Teams
-
Install npm:
npm install
-
Start your project:
npm start
Now, your project is running on https://localhost:3978 which you've been tunneling with ngrok.
5. Test your project on Microsoft Teams
-
Go to Microsoft Teams and login with your M365 developer account.
-
Select
...
button on the left hand side menu and search forApp Studio.
Install and open App Studio. -
Go to
Manifest Editor
and choose+ Create a new app
on the left hand side menu. -
Fill the
App details
fields as following:- Short name: Give your app a short name
- Full name: Give your app a full name
- App ID: Click on
Generate
and your App ID will be generated - Package Name: com.microsoft.teams.app
- Version: 1.0.0
- Short description: Enter a short description for your app
- Full description: Enter a full description for your app
- Developer/Company Name: Enter a company or developer name
- Website: Copy your
https://{subdomain}.ngrok.io
- MPN ID: Skip this part or provide your the Microsoft Partner Network ID
- Privacy statement:
https://{subdomain}.ngrok.io/privacy
- Terms of use:
https://{subdomain}.ngrok.io/termsofuse
-
Click on
Bots
tab on the left side underCapabilities
. ChooseSet up
and complete the setup as following:- Choose Existing bot
- Bot ID: Select from my existing bots
- Find the bot you created in step 3.
- Scope: Personal
and
Save
. YourBot ID
,Password
andBot endpoint address
should automatically appear in this page. -
Go to
Domains and permissions
tab on the left hand side menu underFinish
section. Enter yourNgrok URL
in the Enter a valid domain and click onAdd
. -
Select
Test and distribute
on the left hand side menu underFinish
section and click onInstall
. -
Now, your bot is working on Microsoft Teams and it will appear on the personal chat. You can test your bot by chatting. Some of the example questions you may ask:
"Hello",
"Get me my customer list",
"Who is the latest customer",
"Help",
"Can you breathe",
"How old are you",
...
If you need any reference for Teams app manifest, you may review manifest sample.json under the Teams project folder.