Azure rocks. But sometime we need Host our own DirectLine & Bot Framework without Azure.
For example, test webchat with no internet. :)
Actually, the DirectLine is a bridge that connects your bot and your client. This project (InDirectLine) is a custom implementation of my own written using ASP.NET Core.
For more details, see Direct Line API 3.0
- REST API for normal messages
- WebSocket support
- Attachment support
- Basic support : allow uploading
- allow download
- Security
- Token Generate & Refresh API
- Any user can only access his own conversation data
- Persistene Layer & InMemory storage & clean up resources automatically
- Wechat MP support
- Unit Tests
Typically, InDirectLine will be used as an standlone server (Itminus.InDirectLine.Web). In this way, the InDirectLine & your Bot are two different processes. You could create your Bot in C#/Node.js/Python/Java languages as you like.
In order to use Directline with WebChat, we need create a directLine instance by WebChat.createDirectLine() firstly:
<div id="webchat" role="main"></div>
<script src="https://cdn.botframework.com/botframework-webchat/latest/webchat-minimal.js"></script>
<script>
var userId ="User-"+ parseInt(Math.random()* 1000000);
var userName = userId;
fetch('/v3/directline/tokens/generate', {
method: 'POST',
headers:{
"Content-Type":"application/json",
},
body: JSON.stringify({ userId: userId, password: ""}),
})
.then(res => res.json())
.then(res => {
var directLine = window.WebChat.createDirectLine({
domain: "/v3/directline",
token: res.token,
});
window.WebChat.renderWebChat({
directLine: directLine,
userID: userId,
username: userName,
locale: 'en-US',
}, document.getElementById('webchat'));
});
</script>Note the domain has no trailing slash /.
The WebChat will use WebSocket by default. If you want a REST way, set the webSocket=false:
var directLine = window.WebChat.createDirectLine({
domain: "http://localhost:3000/v3/directline",
token: 'YOUR_DIRECT_LINE_TOKEN',
webSocket:false,
});See Itminus.InDirectLine.IntegrationBotSample.
The InDirectLine reads the appsettings.json file by default, which means it should listen on http://localhost:3000 and assumes that the http://127.0.0.1:5000/api/messages is the bot message endpoint.
You could create a appsettings.Development.json or a appsettings.Production.json and configure the options as you like. To use other ports, see Itminus.InDirectLine.IntegrationBotSample.
Also you could pass the settings by command line arguments or by environment variables.
For more details, see Microsoft Docs.

