-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #123 from AdarshNaidu/unread-messages-intent
[Update] Unread messages intent
- Loading branch information
Showing
17 changed files
with
1,353 additions
and
176 deletions.
There are no files selected for viewing
This file contains 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
33 changes: 33 additions & 0 deletions
33
lambda/custom/handlers/Channels/GetMentionsIntentHandlers.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const { ri } = require('@jargon/alexa-skill-sdk'); | ||
|
||
const helperFunctions = require('../../helperFunctions'); | ||
|
||
const GetMentionsIntentHandler = { | ||
canHandle(handlerInput) { | ||
return handlerInput.requestEnvelope.request.type === 'IntentRequest' && | ||
handlerInput.requestEnvelope.request.intent.name === 'GetMentionsIntent'; | ||
}, | ||
async handle(handlerInput) { | ||
try { | ||
const { | ||
accessToken, | ||
} = handlerInput.requestEnvelope.context.System.user; | ||
|
||
const headers = await helperFunctions.login(accessToken); | ||
const speechText = await helperFunctions.getAllUnreadMentions(headers); | ||
const repromptText = ri('GENERIC_REPROMPT'); | ||
|
||
return handlerInput.jrb | ||
.speak(speechText) | ||
.speak(repromptText) | ||
.reprompt(repromptText) | ||
.getResponse(); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
}, | ||
}; | ||
|
||
module.exports = { | ||
GetMentionsIntentHandler, | ||
}; |
This file contains 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
33 changes: 33 additions & 0 deletions
33
lambda/custom/handlers/Channels/GetUnreadsIntentHandler.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const { ri } = require('@jargon/alexa-skill-sdk'); | ||
|
||
const helperFunctions = require('../../helperFunctions'); | ||
|
||
const GetUnreadsIntentHandler = { | ||
canHandle(handlerInput) { | ||
return handlerInput.requestEnvelope.request.type === 'IntentRequest' && | ||
handlerInput.requestEnvelope.request.intent.name === 'GetUnreadsIntent'; | ||
}, | ||
async handle(handlerInput) { | ||
try { | ||
const { | ||
accessToken, | ||
} = handlerInput.requestEnvelope.context.System.user; | ||
|
||
const headers = await helperFunctions.login(accessToken); | ||
const speechText = await helperFunctions.getAllUnreads(headers); | ||
const repromptText = ri('GENERIC_REPROMPT'); | ||
|
||
return handlerInput.jrb | ||
.speak(speechText) | ||
.speak(repromptText) | ||
.reprompt(repromptText) | ||
.getResponse(); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
}, | ||
}; | ||
|
||
module.exports = { | ||
GetUnreadsIntentHandler, | ||
}; |
This file contains 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
46 changes: 46 additions & 0 deletions
46
lambda/custom/handlers/Channels/ReadMentionsIntentHandler.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
const { ri } = require('@jargon/alexa-skill-sdk'); | ||
|
||
const helperFunctions = require('../../helperFunctions'); | ||
|
||
const ReadMentionsIntentHandler = { | ||
canHandle(handlerInput) { | ||
return handlerInput.requestEnvelope.request.type === 'IntentRequest' && | ||
handlerInput.requestEnvelope.request.intent.name === 'ReadMentionsIntent'; | ||
}, | ||
async handle(handlerInput) { | ||
try { | ||
const { | ||
accessToken, | ||
} = handlerInput.requestEnvelope.context.System.user; | ||
|
||
const headers = await helperFunctions.login(accessToken); | ||
|
||
const channelName = handlerInput.requestEnvelope.request.intent.slots.channelname.value; | ||
const bestMatchingChannel = await helperFunctions.resolveChannelname(channelName, headers, true); | ||
const channel = bestMatchingChannel[0]; | ||
|
||
let count; | ||
if (channel.type === 'c') { | ||
count = await helperFunctions.getUnreadMentionsCountChannel(channel.name, headers); | ||
} else { | ||
count = await helperFunctions.getUnreadMentionsCountGroup(channel.id, headers); | ||
} | ||
|
||
const speechText = await helperFunctions.readUnreadMentions(channel.id, channel.name, count, headers); | ||
const repromptText = ri('GENERIC_REPROMPT'); | ||
|
||
return handlerInput.jrb | ||
.speak(speechText) | ||
.speak(repromptText) | ||
.reprompt(repromptText) | ||
.getResponse(); | ||
|
||
} catch (error) { | ||
console.error(error); | ||
} | ||
}, | ||
}; | ||
|
||
module.exports = { | ||
ReadMentionsIntentHandler, | ||
}; |
89 changes: 89 additions & 0 deletions
89
lambda/custom/handlers/Channels/ReadPinnedMessagesIntentHandlers.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
const { ri } = require('@jargon/alexa-skill-sdk'); | ||
const { login, resolveChannelname, readPinnedMessages } = require('../../helperFunctions'); | ||
const titleMessageBoxTemplate = require('../../APL/templates/titleMessageBoxTemplate'); | ||
const { supportsAPL } = require('../../utils'); | ||
|
||
const ReadPinnedMessagesIntentHandler = { | ||
canHandle(handlerInput) { | ||
return handlerInput.requestEnvelope.request.type === 'IntentRequest' && | ||
handlerInput.requestEnvelope.request.intent.name === 'ReadPinnedMessagesIntent' | ||
&& handlerInput.requestEnvelope.request.dialogState === 'COMPLETED'; | ||
}, | ||
async handle(handlerInput) { | ||
try { | ||
const { | ||
accessToken, | ||
} = handlerInput.requestEnvelope.context.System.user; | ||
|
||
const headers = await login(accessToken); | ||
const resolvedChannelDetails = await resolveChannelname(handlerInput.requestEnvelope.request.intent.slots.channelname.value, headers, true); | ||
|
||
const pinnedMessages = await readPinnedMessages(resolvedChannelDetails[0].id, resolvedChannelDetails[0].name, headers); | ||
|
||
// if there were any pinned messages helper function would return an array, otherwise there are no pinned messages | ||
if (!Array.isArray(pinnedMessages)) { | ||
const repromptText = ri('GENERIC_REPROMPT'); | ||
if (supportsAPL(handlerInput)) { | ||
const data = { | ||
title: '', | ||
message: handlerInput.translate(pinnedMessages.key, pinnedMessages.params), | ||
}; | ||
|
||
return handlerInput.jrb | ||
.speak(pinnedMessages) | ||
.speak(repromptText) | ||
.reprompt(repromptText) | ||
.addDirective(titleMessageBoxTemplate(data)) | ||
.getResponse(); | ||
} | ||
|
||
return handlerInput.jrb | ||
.speak(pinnedMessages) | ||
.speak(repromptText) | ||
.reprompt(repromptText) | ||
.getResponse(); | ||
|
||
} | ||
|
||
const no_of_pinned_messages = pinnedMessages.length; | ||
|
||
const speechText = ri('PINNED_MESSAGES.SUCCESS', { no_of_pinned_messages, channelname: resolvedChannelDetails[0].name, username: pinnedMessages[no_of_pinned_messages - 1][0], message: pinnedMessages[no_of_pinned_messages - 1][1] }); | ||
const repromptText = ri('GENERIC_REPROMPT'); | ||
|
||
|
||
if (!supportsAPL(handlerInput)) { | ||
return handlerInput.jrb | ||
.speak(speechText) | ||
.speak(repromptText) | ||
.reprompt(repromptText) | ||
.getResponse(); | ||
} | ||
|
||
|
||
let apltext = ''; | ||
|
||
for (const message of pinnedMessages) { | ||
apltext += `<b>${ message[0] }:</b>${ message[1] }<br><br>`; | ||
} | ||
|
||
const data = { | ||
title: `Pinned Messages in ${ resolvedChannelDetails[0].name }: ${ pinnedMessages.length }`, | ||
message: apltext, | ||
}; | ||
|
||
return handlerInput.jrb | ||
.speak(speechText) | ||
.speak(repromptText) | ||
.reprompt(repromptText) | ||
.addDirective(titleMessageBoxTemplate(data)) | ||
.getResponse(); | ||
|
||
} catch (error) { | ||
console.error(error); | ||
} | ||
}, | ||
}; | ||
|
||
module.exports = { | ||
ReadPinnedMessagesIntentHandler, | ||
}; |
Oops, something went wrong.