Mikael Ken
Mikael Ken

Reputation: 41

How to send and receive a reply to the bot

I have tried to understand the Microsoft SDK reference in how to communicate with the bot but there is simply no clear way shown of interacting with it.. From the documentation this is what I could put down so far:

const { BotFrameworkAdapter } = require('botbuilder');

const adapter = new BotFrameworkAdapter({
    appId: '123',
    appPassword: '123'
});

// Start a new conversation with the user
adapter.createConversation()

Any ideas ?

Upvotes: 0

Views: 380

Answers (1)

ranusharao
ranusharao

Reputation: 1854

The Microsoft Bot Framework makes use of the restify server to create an API endpoint for the bot. A bot is simply a web service that will send and receive messages to and from the Bot Connector. You will have to use the following steps to communicate with the bot:

  • Install Restify
  npm install --save restify
  • Include the restify module
  const restify = require('restify');
  • Set up the restify server

    const server = restify.createServer();
    server.listen(process.env.port || process.env.PORT || 3978,
        function () {
            console.log(`\n${ server.name } listening to ${ server.url }`);
        }
    );

  • Create the main dialog (here the example uses Echo Bot)
const bot = new EchoBot();
  • Create a POST endpoint for your server and hook up the adapter to listen for incoming requests
server.post('/api/messages', (req, res) => {
    adapter.processActivity(req, res, async (context) => {
        // route to main dialog.
        await bot.run(context);
    });
});

Hope this helps.

Upvotes: 2

Related Questions