AWS cognito user pools, custom message lambda - javascript

Good day to everyone.
I have a problem with AWS cognito user pools custom message which is created inside lambda function as a trigger (custom message lambda). Message with verification link inside. In particular I'm setting message subject to "Custom subject" (and email has this subject), and message body to "Use this {##Custom link##} instead" (and the message is not appear in the body, but the one from user pools web interface is used).
My code is:
public void handleRequest(InputStream input, OutputStream output, Context context) throws IOException {
JsonNode json = parseJsonFromStream(input);
ObjectNode jsonWithResponse = (ObjectNode) json;
jsonWithResponse.with("response").put("emailMessage", "Use this {##Custom link##} instead");
jsonWithResponse.with("response").put("emailSubject", "Custom subject");
try (Writer w = new OutputStreamWriter(output, "UTF-8")) {
w.write(jsonWithResponse.toString());
}
}
I had tried to set even {####} instead {##Link text##} and still same. I'm almost sure it worked some time ago (and I don't remember I changed anything). Does anyone has any idea where should I take a look (dig). As I spent too much time on that and neither missing something (hopefully) small or they have some changes/issues.
P.S. lambda test success. Lambda output looks fine (I eliminate logger here).
Upd: (logger output with response)
OUTPUT JSON is
{
"version": "1",
"region": "eu-west-1",
"userPoolId": "****",
"userName": "*****",
"callerContext": {
"awsSdkVersion": "aws-sdk-android-2.6.7",
"clientId": "****"
},
"triggerSource": "CustomMessage_SignUp",
"request": {
"userAttributes": {
"sub": "****",
"email_verified": "false",
"cognito:user_status": "UNCONFIRMED",
"nickname": "Yaroslav",
"email": "****"
},
"codeParameter": "{####}",
"usernameParameter": null
},
"response": {
"emailMessage": "Use this {##Custom link##} instead",
"emailSubject": "Custom subject"
}
}
Upd2 (JS trigger):
I added code on js (new trigger for custom email) based on example and that works for custom email when user wants confirmation code, but that doesn't work for confirmation link. Again, I tried {##link##} for the link.

So what I ended up with is to use code confirmation. In this case custom email works as expected.
To prevent the user from typing the password into the app, I sent email with custom link, which include the code parametr. Custom link pointed to API Gateway which had corresponding lambda to handle everything and finish the user registration.

Related

aws personalize putevents does not update recommendations

I'm trying to use AWS Personalize. After creating dataset and batch inference, I am updating the user-item-interactions with personalize.putEvents (using Javascript SDK, docs)
Snippet:
const awsOpts = { apiVersion, accessKeyId, secretAccessKey, region }
const pEvents = new AWS.PersonalizeEvents(awsOpts)
// ...
const params = {
trackingId, userId, sessionId,
eventList: [{
eventId: (+sentAt) + "",
sentAt,
eventType,
properties: { itemId }
}]
}
pEvents.putEvents(params, (err, data) => err ? reject(err) : resolve(data))
The events seem to be registered. No errors. After that when I create another batch-inference, I would expect that the new user-items would not appear in the recommendations anymore. But the recommendations in the next batch-inference are unchanged. Am I doing something wrong or am I misunderstanding the putEvents-API-call?
Schema for reference:
{
"type": "record",
"name": "Interactions",
"namespace": "com.amazonaws.personalize.schema",
"fields": [
{
"name": "USER_ID",
"type": "string"
},
{
"name": "ITEM_ID",
"type": "string"
},
{
"name": "EVENT_TYPE",
"type": "string"
},
{
"name": "TIMESTAMP",
"type": "long"
}
],
"version": "1.0"
}
One thing seems a bit strange: Cloud watch reports that the lambda was executed twice despite no errors nor timeout exceeded (timeout is set to 10s, and the lambda takes less than 2s). Also Retry attempts is set to 2.
#D.J.Duff (sadly I can't comment)
Are you sure the events added using PutEvent API are considered without retraining ? I have been through the AWS Personalize Doc looking for exactly that and it looked to me that you need to retrain to get those events included and for the runtime api to be able to consider them. Could you point to me where you saw that they are considered without having to retrain ? Thanks
User-item recommendations, at least from the runtime API should change without retraining after some events (that is what it is for and that is how we use it), though perhaps (it is something to check) you need to use the runtime API to see the new recommendations.
(edited to clarify that that the API is called the "runtime" API - thanks to PatrykMilewski for seeking the clarification - and that I am by no means certain that the particular API used is the important thing - I do know that when using the runtime API, the events do have an effect though).
I have tried out the very same usecase with personalize using boto3 sdk. Yes!! Put events can be used to update user-item-interactions. No need to retrain the model after put events. Looks like aws personalize solutions are made compatible to handle the data updated with put events. When I run the next batch inference, after updating interactions with put events API, I could see the change in the recommendations. I verified this with personalized ranking recipe. I could see the recent interacted items getting re-ranked according users recent interactions.

Handling Null in Alexa

I submitted a skill for Alexa and I got the following error from the Amazon team:
Issue: [StateIntent] Intent, [State] slot
Steps To Reproduce:
User: "Alexa open states symbols"
Skill: "Welcome to state symbols. Give me the name of a state and I will give you symbols used by the state. You can also say random before the state to get a random symbol or ask for specific information for a symbol for a state. I have information about state dog, state flower, state motto, state song, state tree, state bird and state mineral"
User: "tell me about {}"
Skill: "There was a problem with the requested skill's response"
In other words I am not handling situations where the slot is null. I tried several different things to address null in my code but all of them came back with the same error how can I address this? This is a sample section of the code.
function handleStateResponse(intent, session, callback){
var state = intent.slots.State.value.toLowerCase( );
if (!states[state]){
var speechOutput= `I couldn't find that state would you like to ask about another state?`;
var repromptText = `Please try again`;
var header =`not found`;
}else{
var state_dog = states[state].state_dog;
speechOutput = `${capitalizeFirst(state)}'s state dog is the ${state_dog}`;
repromptText = `Would you like to learn about another state?`;
header =capitalizeFirst(state);
}
var shouldEndSession=false;
callback(session.attributes, buildSpeechletResponse(header, speechOutput, repromptText, shouldEndSession));
First things first. If you are not already logging your incoming requests you should do so. It includes valuable information to the request(ie intents, slots, IDs...). Here you can see the structure of the different request types.
Ok, back in your user scenario the user leaves the slot empty. In other words Alexa sends a request to your lambda function with an empty slot. which looks something like this.
{
"type": "IntentRequest",
"intent": {
"name": "StateIntent",
"confirmationStatus": "NONE",
"slots": {
"State": {
"name": "State",
"confirmationStatus": "NONE"
}
}
}
}
When Alexa sends a request with an empty slot it does not include a value member in your 'State'-object.
So to test for this. You only have to put one if-clause.
if (intent.slots.State.value) {
// *Here you can check if the value is right or just continue with the state_dog part*
}
else {
// *Here you can prepare the callback params for 'empty slot'*
}
I hope this helps and good luck with your certification.

How do I add an action to watson conversation response?

I've created intent, entity and dialog without a problem. But right now I'm trying to make it so when the user send "goodbye", the application would close. According to the doc, I'll have to name an action that goes along with an intent. How do I do that? Is it through code or through the conversation workspace platform?
You can use context variables or action variables for that.
How to use context variables? Add in your Advance response the "context" and the values, check my example.
I've used the conversation simple for that.
In your Watson Developer Cloud - IBM Bluemix - Watson Conversation, add in the Advanced response this JSON example, Assuming it is in this conversation node that your application will do something:
{
"context": {
"verified": true;
},
"output": {
"text": {
"values": [
"Please wait and I'll verified your request."
],
"selection_policy": "sequential"
}
}
}
Example (app.js):
function updateMessage(input, data, req, res) {
if (data.context.verified === true){
searchRequest(data, req, res);
} else if (data.output && data.output.text) {
return res.json(data);
}
return data;
}
You can use the data for sending something within conversation flow.
function searchRequest(data, req, res){
// something to do and return value
var sendRequest = "Thanks for wait, the request is" + valueRequest;
data.output.text[0] = sendRequest;
return data;
}
EDIT:
You can add one JSON object like "action", and your code will recognize this variable, with the same example that #Mikko said. And you can check this with:
data.output.action === 'close'
See more about Context variables.
See more about Building a dialog.
You need to be careful with context variables as your next dialog node may or may not update them. Another option is to add a custom variable in the output. This is the solution used in conversation-discovery samples available in the GitHub.
"output": {
"text": {
"values": [
"Goodbye..."
],
"selection_policy": "sequential"
},
"action": "close"
}
Please note that this will cause a warning when closing the JSON editor.

Chrome App Notifications

I am trying to create a function that displays a chrome notification from my app when an update is available. I typed it all up and it just doesn't work.
function updatenotification() {
chrome.notifications.create(memeNotification, {
"type": "basic",
"iconUrl":"icons/icon48.png",
"title": "Update Available!",
"message": "There is an update available for Meme Music Board!"
});
};
Here is what I have. It is supposed to be triggered by the onUpdateAvailable api. However, no matter how I try to trigger the function it does NOT make a notification. I cannot even get any notifications to display. I have added the notifications permission to the manifest. I have tried it in my background.js as well as my main javascript. I am at my wits end. Any help would be wonderful. Thank you.
Edit!
I have also tried:
var options = {
type : "basic",
title: "Update Available",
message: "An Update is available",
expandedMessage: "An Update is available for Meme Music Board",
},
function notify() {
chrome.notifications.create(options);
},
And for some reason it just does not work. This method works on other apps made by others.

Azure Graph api user creation - property values specified are invalid

I have a problem with Azure AD Graph API integration where we try to create user to existing Active directory. Used azure documentation to work on this (https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#UpdateUser)
For some reason the example dataset is not working, but I'm receiving:
{
"odata.error": {
"code": "Request_BadRequest",
"message": {
"lang": "en",
"value": "One or more property values specified are invalid."
},
"values": null
}
}
The dataset I'm passing is
{
"accountEnabled": true,
"displayName": "Test User",
"mailNickname": "TestUser",
"passwordProfile": {
"password": "Test1234",
"forceChangePasswordNextLogin": false
},
"userPrincipalName": "Test#_MY_DOMAIN_.onmicrosoft.com"
}
_MY_DOMAIN_ is one of the domains defined in the Active directory's domains.
If I try e.g. removing any of the required fields, I'm receiving error which defines the missing property.
Listing and updating users is working just fine, there is some weird issue with adding.
Usually, we will get this issue when we haven't set the Url in the correct format. I tested your dataset on my side, it worked fine. Please double check the url.
Here is the capture of my test request:
Any further concern, please feel free to let me know.
Most probably problem was related to Azure AD permissions. Somehow started suddenly working.
One thing figured out is that the error message above will also come e.g. if you have property key mistyped. Sometimes response describes the missing property, but not always.
Thanks everyone for your time..

Categories

Resources