📜 ⬆️ ⬇️

Microsoft Bot Framework on Linux under Node.JS

To create and run our first chat bot using Microsoft's Bot Framework Microsoft's Bot Framework for Linux, we need to install the following components:


After creating the simplest bot, we will analyze how you can run and debug it.

Installing Node.JS


The installation commands given here are suitable for Debian / Ubuntu / Mint distributions, for the rest of the instructions you can find here . In the terminal, run the following commands:
')
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash - sudo apt-get install -y nodejs sudo apt-get install -y build-essential 

Installing Bot Framework Emulator for Linux


Bot Framework Emulator we need to debug our bot. Open the next page in the browser. In the terminal, we check the architecture of your car with the command:

 arch 

According to the architecture, we download the corresponding file from the Github page, in my case it is the file:

 botframework-emulator-3.5.29-x86_64.AppImage 

After downloading, add the file permissions to execute and run.

Installing Visual Studio Code


Installs easily in a couple of clicks on this link .

Creating our first chat bot


Open the Visual Studio Code, select the new folder in which the project will be located and launch the internal terminal: Ctrl-` . We recruit a team to create a new project:

 npm init 

Press Enter several times then yes . Now install the 2 packages node.js: botbuilder and restify commands:

 npm install --save botbuilder npm install --save restify npm install --save dotenv-extended 

Here in the same folder in VS Code (or any other editor) create the app.js file and add the following code to it:

Echo bot code
 // This loads the environment variables from the .env file require('dotenv-extended').load(); var restify = require('restify'); var builder = require('botbuilder'); // Setup Restify Server var server = restify.createServer(); server.listen(process.env.port || process.env.PORT || 3978, function () { console.log('%s listening to %s', server.name, server.url); }); // Create chat connector for communicating with the Bot Framework Service var connector = new builder.ChatConnector({ appId: process.env.MICROSOFT_APP_ID, appPassword: process.env.MICROSOFT_APP_PASSWORD }); // Listen for messages from users server.post('/api/messages', connector.listen()); // Receive messages from the user and respond by echoing each message back (prefixed with 'You said:') var bot = new builder.UniversalBot(connector, function (session) { session.send("You said: %s", session.message.text); }); 


We save the file, now we are ready to launch and debug our bot.



Run and debug chat bot


You can start the bot in the terminal with the command:

 node app.js 

Or in the Visual Studio Code Debugger - F5 . To set a breakpoint, move the cursor to the desired line and press - F9 . After launching the bot, we return to the emulator, connect to the address http://127.0.0.1:3978/api/messages and type: Hi and see the answer of our bot:



That's all. More complex examples of building bots on node.js can be found here .

PS It would be interesting to write a similar article with reference to C # /. NET Core under Linux, but it seems that BotBuilder is not yet ready for .NET Core , although the work is underway and there is some success as the full .NET 4.6 infrastructure becomes available for. NET Core.

Source: https://habr.com/ru/post/333824/


All Articles