Unfortunately Unity and WebGL do not support multithreading but this implementation allows you to easily integrated a microsoft direct line bot to a unity project.
- Listen to messages via WebSocket connection
- Support for WebGL (also WebSocket)
- Receive text and attachments
- Easy to customize
Simply clone or download this repository and open the project with Unity 2019.1.5f1 (you can use any other version of unity but for best result and no errors you should take a look at it with the version I developed the project).
Make sure to get the secret key of the direct line bot you want to connect. Here is how to get the secret key: https://docs.microsoft.com/en-gb/azure/bot-service/bot-service-channel-connect-directline?view=azure-bot-service-4.0
- Open the project with Unity
- Open the scene called "Main"
- Find the GameObject called DirectLineConnection and enter your secret key in the field provided
- Press play and communicate with your bot
- Watch console for detailed information
using DirectLine;
DirectLineConnection.instance.Initialize();
DirectLineConnection.instance.SendMessage("Hello Bot");
- This one is crucial! In order to achieve a valid connection via WebSocket in WebGL YOU SHOULD NEVER change the name of the GameObject called DirectLineConnection. The custom javascript library (.../Assets/Plugins/WebSocket.jslib) requieres an object with excatly this name to send back messages from WebGL JavaScript.