剛接觸 NodeJS,紀錄一下
//============匯入Modules============
var restify = require('restify');
var builder = require('botbuilder');
//============讀取config============
var fs = require('fs');
var config = fs.readFileSync(__dirname + '/config.json','utf8'); //__dirname -->localpath
//============建立Server============
var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978);
//============建立Bot============
var connector = new builder.ChatConnector({
appId:config.appId, //bot framework appId
appPassword:config.appPassword //bot framework appPassword
});
var bot = new builder.UniversalBot(connector);
server.post('/api/messages', connector.listen()); //----->這個要記住
//============建立Bot對話============
bot.dialog('/',
[function(session)
{
session.send("Hi,I am bot ~");
builder.Prompts.text(session,'What\'s your name ?');
},
function(session,result)
{
session.send('Nice to meet you ,'+ result.response);
}]
);