Skip to content

Commit

Permalink
chore(bot): remove useless starter-kit code
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Blancher committed Oct 4, 2017
1 parent feb26d8 commit d0528d6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 63 deletions.
69 changes: 7 additions & 62 deletions bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,9 @@ const recastClient = new r(process.env.REQUEST_TOKEN)

let sessionId = null
let endConv = false

let done = null

let reply = (text, done) => {
}

let sendSMS = (body) => {
const twilioUrl = 'https://api.twilio.com/2010-04-01/Accounts/ACff4221972b56e6f75223039c9648fd49/Messages.json'
const to = '+33635917428'
const from = '+33756798311'
const appId = 'ACff4221972b56e6f75223039c9648fd49'
const appSecret = '78d40a89c33b453ed1aa128920971860'

request.post(twilioUrl).form({'To': to, 'From': from, 'Body': body}).auth(appId, appSecret)
}


// Format reply for Alexa
let alexaReply = (text) => {
done.send({
response: {
Expand All @@ -45,14 +31,14 @@ let handleAlexaMessage = (text) => {
'thanks',
]

// Send input to Recast.AI
recastClient.request.converseText(text, { conversationToken: sessionId })
.then((res) => {

// Handle special cases
console.log(res)
if (res.action && res.action.slug == 'sms-report') {
sendSMS("Your account balance is +$2340,25.\nYour last expense is $50 at Marks & Spencer PLC.\nHave a great day!\nYour banking assistant.")
} else if (res.action && endIntents.indexOf(res.action.slug) > -1) {

// Set end conversation flag to true when we match an end intent, so Alexa stop listening continously
if (res.action && endIntents.indexOf(res.action.slug) > -1) {
console.log('End of conversation')
endConv = true
}
Expand All @@ -65,44 +51,6 @@ let handleAlexaMessage = (text) => {
done.send(err)
})
}
/*
let handleBCMessage = (message) => {
// Get text from message received
const text = message.content
console.log('I receive: ', text)
// Get senderId to catch unique conversation_token
const senderId = message.senderId
// Call Recast.AI SDK, through /converse route
recast.converseText(text, { conversationToken: senderId })
.then(result => {
if (result.action) {
console.log('The conversation action is: ', result.action.slug)
}
// If there is not any message return by Recast.AI for this current conversation
if (!result.replies.length) {
message.addReply({ type: 'text', content: 'I don\'t have the reply to this yet :)' })
} else {
// Add each reply received from API to replies stack
result.replies.forEach(replyContent => message.addReply({ type: 'text', content: replyContent }))
}
// Send all replies
message.reply()
.then(() => {
// Do some code after sending messages
})
.catch(err => {
console.error('Error while sending message to channel', err)
})
})
.catch(err => {
console.error('Error while sending message to Recast.AI', err)
})
}*/

exports.bot = (event, doneFct) => {
console.log('Received event:', JSON.stringify(event, null, 2))
Expand All @@ -114,15 +62,12 @@ exports.bot = (event, doneFct) => {
'Welcome back. What do you need?'
]

if (event.message) {
// BC Message
recastClient.connect.handleMessage({ body }, done, handleBCMessage)
} else if (event.request) {
if (event.request) {
console.log('Alexa message received')
// Alexa Message
if (event.request.type == 'LaunchRequest') {
console.log('Trigger word received')
// User says trigger word
// User says invovation word, reply hello
alexaReply(helloReplies[Math.floor(Math.random() * helloReplies.length)])
} else if (event.request.type == 'IntentRequest') {
// Conversation
Expand Down
2 changes: 1 addition & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const bot = require('./bot').bot

// Start Express server
const app = express()
app.set('port', 4000)
app.set('port', 3000)
app.use(bodyParser.json())

// Handle / route
Expand Down

0 comments on commit d0528d6

Please sign in to comment.