How to get the Agent Email Address from amazon connect logged in - amazon-web-services

i have build sample amazon connect login to get the agent details from javascript api, but do not have any docs to get agent email address i followed docs
https://github.com/amazon-connect/amazon-connect-streams/blob/master/Documentation.md
Kindly help me how to get the email adddress

You can get the email address of the User by using the describeUser.
var AWS = require('aws-sdk');
var connect = new AWS.Connect();
exports.handler = function (event) {
var params = {
InstanceId: 'STRING_VALUE', /* required */
UserId: 'STRING_VALUE' /* required */
};
connect.describeUser(params, function(err, data) {
if (err) console.log(err, err.stack);
else console.log(data.User.IdentityInfo.Email);
});
}
From the documentation you posted:
https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Connect.html#describeUser-property
An example of what the User object looks like:
https://docs.aws.amazon.com/connect/latest/APIReference/API_DescribeUser.html

Related

Call AES SES sendEmail from a Alexa skill

I have been trying for weeks now to figure out how to invoke a call to sendEmail from an Alexa-hosted node.js skill. It is a very simple skill where the user makes a selection. when the selection is made I want to send a email to myself with contents of the selection. I have been trying to call sendEmail from my index.js, which contains the logic for my skill. I created a IAM role with the proper .json file as indicated on AWS, and was able to run a basic node file from the aws command line interface that sends me a email. What kind of steps will I have to take to get my Alexa skill to send the email? Can I just invoke the lambda function that is already working from my Alexa skill?
I have been trying to put the code below, and code similar to it without nodemailer doing the basic ses send email. I started with the aws ses webpage. I cannot find a single tutorial that actually walks you through step by step of calling this ses send email function in a Alexa skill and I would be so grateful to be pointed in the right direction.
'''
const Alexa = require('ask-sdk-core');
const AWS = require("aws-sdk");
let nodemailer = require("nodemailer");
let aws = require("#aws-sdk/client-ses");
// configure AWS SDK
process.env.AWS_ACCESS_KEY_ID = "xxxx";
process.env.AWS_SECRET_ACCESS_KEY = "xxxx";
const ses = new aws.SES({
apiVersion: "2010-12-01",
region: "us-east-1",
});
// create Nodemailer SES transporter
let transporter = nodemailer.createTransport({
SES: { ses, aws },
});
// send some mail
transporter.sendMail(
{
from: "xxxx#gmail.com",
to: "xxxx#gmail.com",
subject: "Message",
text: "I hope this message gets sent!",
ses: {
// optional extra arguments for SendRawEmail
Tags: [
{
Name: "tag_name",
Value: "tag_value",
},
],
},
},
(err, info) => {
console.log(info.envelope);
console.log(info.messageId);
}
);
'''
edit: thanks for the responses already guys! The only notable error I am getting is there is a problem with the requested skills response. So my Alexa skill is amazon hosted. Do I have to change this to use SES,sendEmail()? In my lambda page on amazon I have a file in a folder called sendEmail() but that gives me a error about the line AWS = require(etc.. in the debugger with the output "errorMessage": "2021-03-14T00:33:00.315Z e19e74c6-4c00-47dc-9872-77c0a602541a Task timed out after 3.00 seconds" the code I have in the lambda function titled sendEmail is actually the below code. the line sendEmail() also gives there is a problem with the requested skills response from the Alexa. I do not see my Alexa skill in my lambda functions. Do I have to add it in? Sorry, I really am a noob for AWS programming. Thank you!
`AWS = require('aws-sdk');
// Set the region
AWS.config.update({region: 'us-east-1'});
// Create sendEmail params
var params = {
Destination: { /* required */
ToAddresses: [
'x#gmail.com',
/* more items */
]
},
Message: { /* required */
Body: { /* required */
Html: {
Charset: "UTF-8",
Data: "HTML_FORMAT_BODY"
},
Text: {
Charset: "UTF-8",
Data: "TEXT_FORMAT_BODY"
}
},
Subject: {
Charset: 'UTF-8',
Data: 'Test email'
}
},
Source: 'x#gmail.com', /* required */
ReplyToAddresses: [
'pamphl3t#gmail.com',
/* more items */
],
};
// Create the promise and SES service object
var sendPromise = new AWS.SES({apiVersion: '2010-12-01'}).sendEmail(params).promise();
// Handle promise's fulfilled/rejected states
sendPromise.then(
function(data) {
console.log(data.MessageId);
}).catch(
function(err) {
console.error(err, err.stack);
});`
I believe this part of the documentation is what you're looking for. after you put your custom skill on Lambda function you need to send the content of the body to your email:
const querystring = require('querystring');
let post_data = null;
exports.handler = function (event, context) {
post_data = querystring.stringify(event.body);
}
// your emailing code here
Check this repo too
Where are you defining process.env? If you're running in Alexa Hosted, you'll get environment variables for the Alexa-owned IAM role which will have no access to SES.
Have you tried hardcoding the key and secret from your personal AWS account? If that solves it, look at adding the dotenv package in your package.json, and follow its documentation to set the values in a .env file you can add to your .gitignore.
const AWS = require( 'aws-sdk' );
var SES = new AWS.SES( { apiVersion: '2010-12-01', region: 'us-east-1' } );
//when we are sending our email
//we have to return a promise
//this is because the sendEmail funx
//from SES
//is an ASYNCHRONOUS CALL to the simple email server
//we have to wait for this call to complete before RET
//this is the vital line that resolves my issue
if (typeof Promise === 'undefined' ) {
AWS.config.setPromisesDependency( require( 'bluebird' ) );
}
sendEmail("SOME TEXT");
function sendEmail ( text,event, context, callback ){
var link = "";
var params = {
Destination: {
ToAddresses: [ "address#gmail.com" ]
},
Message: {
Body: {
Text: { Data: link
}
},
Subject: { Data: " text + " has arrived!" }
},
Source: "verifiedaddress#gmail.com"
};
return SES.sendEmail( params ).promise();
}

AWS Connect API CORS issue

I am new to AWS and been struggling to find a solution for my problem. I am trying to create a custom chat widget for our website using Amazon Connect and I am using this API to start a chat contact.
I am following this article to create a custom chat widget for our website.
The problem I am facing is the CORS error when I try to start a chat session. I am following this documentation from AWS.
This is what I have so far
<script type="text/javascript">
AWS.config.credentials = new AWS.Credentials({
accessKeyId: "keyId",
secretAccessKey: "secret"
});
AWS.config.region = "us-east-1";
var connect = new AWS.Connect({
apiVersion: '2017-08-08',
region: 'us-east-1',
});
new AWS.Connect(options = {});
var params = {
ContactFlowId: '67324a76-5b54-48a3c1-a0da-c64e26700af9', /* required */
InstanceId: '54b0f2c2-dd64-4ce3a4-973f3f-c3fea84f12c1E', /* required */
ParticipantDetails: { /* required */
DisplayName: 'test_customer' /* required */
},
ClientToken: '',
InitialMessage: {
Content: 'test', /* required */
ContentType: 'string' /* required */
}
};
connect.startChatContact(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
</script>
and this is the error that I get
I really don't have any idea if what I am doing is correct. Please help.
Try going to the AWS Connect in AWS (The actual AWS console not the Connect console).
The click on "Application Integrations" and then "+add origin" and add the url to your custom chat widget.

Lambda function access by RDS trigger creates connection lost

I created 2 tables in RDS aurora:
test-table in aurora db with values id(PK), tasknumber, status , contactid(FK)
contact-table in same db with values contactid(PK), email, phone
I created a trigger in 'test-table' that whenever a 'status' changes, the trigger should call AWS-Lambda ARN.
The Lambda function and Aurora has all the permissions, and security cleared, still on testing from Lambda I get below image error and on updating the 'status' field manually in aurora(via Workbench Sql query) it shows:
Operation failed: There was an error while applying the SQL script to the database.
ERROR 2013: 2013: Lost connection to MySQL server during query
I have attached my Lambda Node.Js code too.
var AWS = require('aws-sdk');
AWS.config.update({ region: 'us-east-1' });
const mysql = require('mysql');
var con = mysql.createConnection({
host: 'correct value',
user: 'root',
password: 'correct value',
port: correct value,
database: 'correct value'
});
exports.handler = (event, context, callback) => {
context.callbackWaitsForEmptyEventLoop = false;
var fk = event.contact_id;
console.log('FOREIGN KEY=', fk)
con.connect(function(err) {
if (err) throw err;
var sql = `SELECT * FROM db.contacts where contact_id=${fk}`
con.query(sql, function(err, result) {
if (err) throw err;
var email = result[0].email;
console.log(email);
var sns = new AWS.SNS();
var params = {
Message: email,
Subject: "Test SNS From Lambda",
TopicArn: "arn:correct value"
};
sns.publish(params, function(err, data) {
if (err) console.log(err, err.stack);
else {
console.log(data);
callback(null, 'Success');
}
});
});
});
};
Image1ErrorMySqlWorkbench
Image2ErrorLambdaaws
Also followed for NodeJs package: https://github.com/isaacs
you have to close the connection if you want the instant response otherwise it will take the default time to close the connection, please let me know if makes sense

User ID in Cognito

I use AWS API Gateway + AWS Cognito (Federated Identity + User Pool). I'm creating REST API in API Gateway. There are methods for getting users list and for getting user by id. What should I use as user ID?
Response should contain te following user data: ID, username, first name, last name etc. Username, first name, last name are stored in User Pool attributes.
I see in examples that they use cognitoIdentityId as User ID. If I will use cognitoIdentityId as ID, then how should I get user data by this ID? Please give me an example or link to API reference how to get user data by cognitoIdentityId.
You should be able to get user attributes as shown in the following example using the Username.
var AWS = require('aws-sdk');
AWS.config.region = 'us-east-1'; //This is required to derive the endpoint
var poolData = { UserPoolId : 'us-east-1_TcoKGbf7n',
ClientId : '4pe2usejqcdmhi0a25jp4b5sh3'
};
var userPool = new AWS.CognitoIdentityServiceProvider.CognitoUserPool(poolData);
var userData = {
Username : 'username',
Pool : userPool
};
var cognitoUser = new AWS.CognitoIdentityServiceProvider.CognitoUser(userData);
cognitoUser.getUserAttributes(function(err, result) {
if (err) {
alert(err);
return;
}
for (i = 0; i < result.length; i++) {
console.log('attribute ' + result[i].getName() + ' has value ' + result[i].getValue());
}
});
Reference: Examples: Using the JavaScript SDK
If you need to query the user attributes using AccessToken, then use the following example.
var params = {
AccessToken: 'STRING_VALUE' /* required */
};
cognitoidentityserviceprovider.getUser(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
Reference: AWS JavaScript SDK GetUser
Note: Currently there is no support in both AWS JavaScript SDK and API to get the user attributes by UserId.

Integrating AWS Lex with Skype

I have created a Chat bot in AWS LEX and want to integrate it with Skype. Is there any way I can achieve that?
I have already implemented it with Facebook, Slack, and Twillo.
I'm trying using LexRuntime,
Microsoft Bot Framework and AWS SDK for Javascript to implement Amazon Lex over skype for business in Node.js.
You can define as:
var AWS = require('aws-sdk');
AWS.config.region = 'us-east-1';
var lexruntime = new AWS.LexRuntime({ apiVersion: '2016-11-28' });
var bot = new builder.UniversalBot(connector, function (session) {
console.log(session.userData);
var params = {
botAlias: '$LATEST', /* required */
botName: 'YourBotName', /* required */
contentType: 'text/plain; charset=utf-8', /* required */
inputStream: session.message.text,//new Buffer('...') || 'STRING_VALUE' || streamObject, /* required */
userId: 'username', /* required */
accept: 'text/plain; charset=utf-8',
sessionAttributes: session.userData /* This value will be JSON encoded on your behalf with JSON.stringify() */
};
console.log(params);
lexruntime.postContent(params, function (err, data) {
if (err) console.log(err, err.stack); // an error occurred
else {
session.userData = data.sessionAttributes;
console.log(data); // successful response
session.send("%s", data.message);
}
});
});
I tested this on emulator provided by Microsoft and getting the response from my Lex Bot.
You can refer PostContent for params content.
There is currently no native support for AWS Lex to integrate with Skype.
However, you can create a middleware that will use a Skype chat bot and forward requests on to AWS Lex. There are a number of different ways to do this so I won't provide any specifics.
Alternatively, Microsoft is also pitching a chatbot framework that is leveraging Cortana.