Bot Framework v4 core bot sample.
This bot has been created using Bot Framework
- .NET Core SDK version 2.1
# determine dotnet version dotnet --version
- Go to Azure portal
- Create Azure's Web App Bot
- In section Channels add DirectLine
- Save DirectLine secret
- Download.PublishSettings file you find in the Azure's Web App pannel
- Copy the userPWD value
- Right click on the Project and click on "Publish..."
- Paste the password you just copied and publish
- Go to appsettings.json
- Change MicrosoftAppId and MicrosoftAppPassword using values from Azure settings
- Change DirectLineSecret with previously saved
- Go to wwwroot. Here you need:
- default.html
- js.js
Request to a HomeController for token generation
const res = await fetch('/api/token/generate', { method: 'POST' });
const { token, conversationId } = await res.json();
Initialize DirectLine object and save conversationId
dl = new DirectLine.DirectLine({
token: token
});
createCookie("conversationId", conversationId, 365);
Request to a HomeController for token refreshing
const response = await fetch('/api/token/refresh?conversationId=' + readCookie("conversationId"), { method: 'GET' });
const refreshData = await response.json();
Initialize chat with refreshing data
dl = new DirectLine.DirectLine({
token: refreshData.token,
streamUrl: refreshData.streamUrl,
webSocket: false,
conversationId: readCookie("conversationId")
});
Then create WebChat object with static userID
window.WebChat.renderWebChat({
directLine: dl,
userID: "default-user"
}, document.getElementById('webchat'));