Last active
November 28, 2017 23:44
-
-
Save brunoluiz/a76a0bef954e5f0be8e2314d3e977e4f to your computer and use it in GitHub Desktop.
medium-botframework-part1-echobot-app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NODE_ENV=development | |
PORT=80 | |
APP_ID= | |
APP_SECRET= |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const builder = require('botbuilder') | |
const dotenv = require('dotenv') | |
const express = require('express') | |
// Instantiate express | |
const app = express() | |
// Load .env configs | |
dotenv.config() | |
// Start Express listener | |
app.listen(process.env.PORT, () => console.log('Up and running!')) | |
// Instatiate the bot connector (will listen to messages) | |
const connector = new builder.ChatConnector({ | |
appId: process.env.APP_ID, | |
appPassword: process.env.APP_SECRET | |
}) | |
// Bind the messages endpoint to the bot connector listener | |
app.post('/api/messages', connector.listen()) | |
// Instantiate the bot interface | |
const bot = new builder.UniversalBot(connector) | |
// Default/Fallback dialog | |
bot.dialog('/', (session) => { | |
// Get the user sent message | |
const message = session.message.text | |
// Echo back the message for the user | |
session.send(message) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment