· 4 years ago · Apr 16, 2021, 03:12 PM
1const InProgressItemTitleGivenfindItemIntentHandler = {
2 canHandle(handlerInput){
3 const request = handlerInput.requestEnvelope.request;
4 return request.type === 'IntentRequest' &&
5 request.intent.name === 'findItemIntent'
6 && handlerInput.requestEnvelope.request.intent.slots.itemTitle.value
7 && !handlerInput.requestEnvelope.request.intent.slots.itemAuthor.value
8 && handlerInput.requestEnvelope.request.dialogState === "COMPLETED";
9 },
10 async handle(handlerInput) {
11 const currentIntent = handlerInput.requestEnvelope.request.intent;
12 const attributesManager = handlerInput.attributesManager;
13 const sessionAttributes = attributesManager.getSessionAttributes();
14 const requestAttributes = handlerInput.attributesManager.getRequestAttributes();
15 const device_location_text = requestAttributes.t('LOCATION_TEXT', requestAttributes.t('SKILL_NAME'), requestAttributes.t('DEVICEID_LOCATION'));
16 const skill_header_title = requestAttributes.t('VINTIS_TITLE');
17
18 try {
19 // Call the progressive response for the user to wait
20 await util.callDirectiveService(handlerInput);
21 } catch (error) {
22 console.log(JSON.stringify(error))
23 }
24
25 let prompt;
26
27 // const slotValues = getSlotValuesAlexaEntities(filledSlots);
28 let itemTitle = handlerInput.requestEnvelope.request.intent.slots.itemTitle.value;
29 //let bookTitleResolved = slotValues.bookTitle.resolved;
30 console.log(itemTitle)
31
32 sessionAttributes.Title = itemTitle;
33 // Run the title through the function to remove all the string articles for database searching in Horizon
34 let itemTitle_api = removeArticles(itemTitle, requestAttributes);
35 // Prepare all of the URLS and endpoint values for the API call
36 let titleKW_params = encodeURIComponent(`titlKW:` + itemTitle_api);
37
38 const url_bib_search = endpoint + `/catalog/bib/search?j=AND&q=` + titleKW_params + `&includeFields=title,author,bib&ct=30`;
39 console.log(url_bib_search)
40
41
42
43 const slots = handlerInput.requestEnvelope.request.intent.slots;
44 if (slots.itemTitle.confirmationStatus === "DENIED") {
45 let prompt = requestAttributes.t('FIND_DENIED_CONFIRMATION_BOOK_PROMPTS');
46 handlerInput.requestEnvelope.request.intent.slots.itemTitle.value = null;
47 return handlerInput.responseBuilder
48 .speak(prompt)
49 .reprompt(prompt)
50 .addElicitSlotDirective('itemTitle')
51 .getResponse();
52
53 } else if (slots.itemTitle.confirmationStatus === "CONFIRMED") {
54
55 return handlerInput.responseBuilder
56 .speak("Testing")
57 .reprompt("Testing")
58 .getResponse();
59 }
60 }
61};
62
63
64
65// Then for the progressive response, I am just exporting it from the Utils.js
66const AWS = require('aws-sdk');
67
68const s3SigV4Client = new AWS.S3({
69 signatureVersion: 'v4',
70 region: process.env.S3_PERSISTENCE_REGION
71});
72
73module.exports = {
74 getS3PreSignedUrl(s3ObjectKey) {
75
76 const bucketName = process.env.S3_PERSISTENCE_BUCKET;
77 const s3PreSignedUrl = s3SigV4Client.getSignedUrl('getObject', {
78 Bucket: bucketName,
79 Key: s3ObjectKey,
80 Expires: 60*1 // the Expires is capped for 1 minute
81 });
82 console.log(`Util.s3PreSignedUrl: ${s3ObjectKey} URL ${s3PreSignedUrl}`);
83 return s3PreSignedUrl;
84
85 },
86 callDirectiveService(handlerInput) {
87 // Call Alexa directive Service.
88 const {requestEnvelope} = handlerInput;
89 const directiveServiceClient = handlerInput.serviceClientFactory.getDirectiveServiceClient();
90 const requestId = requestEnvelope.request.requestId;
91 const {apiEndpoint, apiAccessToken} = requestEnvelope.context.System;
92
93 // build the progressive response directive to be returned.
94 const directive = {
95 header: {
96 requestId,
97 },
98 directive: {
99 type: 'VoicePlayer.Speak',
100 speech: '<speak> Let me see what I can find for you.... <break time="0.5s" /></speak>'
101 },
102 };
103
104 // send the directive
105 return directiveServiceClient.enqueue(directive, apiEndpoint, apiAccessToken);
106 }
107}