I am trying to execute a basic dialog example for the Microsoft bot framework, but getting a strange error and am unable to proceed
node index.js
(node:8600) [DEP0040] DeprecationWarning: The punycode
module is deprecated. Please use a userland alternative instead.
(Use node --trace-deprecation ...
to show where the warning was created)
(node:8600) [DEP0111] DeprecationWarning: Access to process.binding(‘http_parser’) is deprecated.
(node:8600) [DEP0111] DeprecationWarning: Access to process.binding(‘http_parser’) is deprecated.
const querystring = require('querystring')
const https = require('https')
module.exports = {
executeSearch: function (query, callback) {
this.loadData('/search/users?q=' + querystring.escape(query), callback)
},
loadProfile: function (username, callback) {
this.loadData('/users/' + querystring.escape(username), callback)
},
loadData: function (path, callback) {
const options = {
host: 'api.github.com',
port: 443,
path: path,
method: 'GET',
headers: {
'User-Agent': 'gitbot',
},
}
const request = https.request(options, function (response) {
let data = ''
response.on('data', function (chunk) {
data += chunk
})
response.on('end', function () {
callback(JSON.parse(data))
})
})
request.end()
},
}
const builder = require('botbuilder')
const restify = require('restify')
const githubClient = require('./github-client')
const connector = new builder.ChatConnector()
// session
// const bot = new builder.UniversalBot(connector, [
// (session) => {
// session.send('Hello World!')
// },
// ]).set('storage', new builder.MemoryBotStorage())
//dialog
const bot = new builder.UniversalBot(connector).set(
'storage',
new builder.MemoryBotStorage()
)
const dialog = new builder.IntentDialog()
dialog.matches(/^search/i, [
function (session, args, next) {
if (session.message.text.toLowerCase() === 'search') {
builder.Prompts.text(session, 'Who are you looking for?')
} else {
let query = session.message.text.substring(7)
next({ response: query })
}
},
function (session, result, next) {
let query = result.response
if (!query) {
session.endDialog('Request cancelled')
} else {
githubClient.executeSearch(query, function (profiles) {
let totalCount = profiles.total_count
if (totalCount === 0) {
session.endDialog('Sorry, no results found.')
} else if (totalCount > 10) {
session.endDialog(
'More than 10 results were found. Please provide a more restrictive query.'
)
} else {
session.dialogData.property = null
let usernames = profiles.items.map(function (item) {
return item.login
})
builder.Prompts.choice(
session,
'What user do you want to load?',
usernames
)
}
})
}
},
function (session, result, next) {
let username = result.response.entity
githubClient.loadProfile(username, function (profile) {
let card = new builder.ThumbnailCard(session)
card.title(profile.login)
card.images([builder.CardImage.create(session, profile.avatar_url)])
if (profile.name) {
card.subtitle(profile.name)
}
let text = ''
if (profile.company) {
text += profile.company + ' n'
}
if (profile.email) {
text += profile.email + ' n'
}
if (profile.bio) {
text += profile.bio
}
card.text(text)
card.tap(new builder.CardAction.openUrl(session, profile.html_url))
let message = new builder.Message(session).attachments([card])
session.send(message)
})
},
])
bot.dialog('/', dialog)
const server = restify.createServer()
server.post('/api/messages', connector.listen())
server.listen(3978)