How to update agent status from lambda function - amazon-web-services

I am working on Amazon Connect application. I am using lambda for handling backend data. My requirement is to change agent status from lambda call using AWS SDK/Stream API. I know we can do this from Amazon Connect stream api via CCP. But in my case, it needs to be done from lambda call. I checked documentation of AWS Connect SDK but there is not direct method available for changing Agent state.
Kindly suggest.
Thanks,
gans

You can directly set the agent state using the Amazon Connect Streams API:
var state = agent.getAgentStates()[0];
agent.setState(state, {
success: function() { /* ... */ },
failure: function(err) { /* ... */ }
});
Reference: https://github.com/amazon-connect/amazon-connect-streams/blob/master/Documentation.md#agent-api

The April 2022 Connect release has added an API call to do this finally!
There is now a PutUserStatus operation that will update a given agents status.
The call to the operation in javascript is:
const AWS = require('aws-sdk');
const connect = new AWS.Connect();
let params = {
AgentStatusId: 'STRING_VALUE', /* required */
InstanceId: 'STRING_VALUE', /* required */
UserId: 'STRING_VALUE' /* required */
};
connect.putUserStatus(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
where:
UserId is the guid identifier of the user.
InstanceId is the guid identifier of the Amazon Connect instance.
AgentStatusId — the guid identifier of the agent status. This can be retrieved via the listAgentStatuses operation.
More info here:
https://docs.aws.amazon.com/connect/latest/APIReference/API_PutUserStatus.html

Related

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.

GCP cloud function to suspend and resume the GCP instances

We can use GCP cloud functions to start and stop the GCP instances but I need to work on scheduled suspend and resume of GCP instances using cloud function and scheduler.
From GCP documentation, I got that we can do start and stop using cloud functions available below
https://github.com/GoogleCloudPlatform/nodejs-docs-samples/tree/master/functions/scheduleinstance
Do we have same node JS or other language Pcgks available to suspend and resume GCP instances?
If not can we create our own for suspend/resume.
When I tried one I got below error
"TypeError: compute.zone(...).vm(...).resume is not a function
Edit, thanks Chris and Guillaume, after going through you links i have edited my code and below is my index.js file now.
For some reason when I do
gcloud functions deploy resumeInstancePubSub --trigger-topic resume-instance --runtime nodejs10 --allow-unauthenticated
i always get
Function 'resumeInstancePubSub1' is not defined in the provided module.
resumeInstancePubSub1 2020-09-04 10:57:00.333 Did you specify the correct target function to execute?
i have not worked on Node JS Or JS before, I was expecting something similar to start/stop documentation which I could make work easily using below git repo
https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git
My index.js file,
// BEFORE RUNNING:
// ---------------
// 1. If not already done, enable the Compute Engine API
// and check the quota for your project at
// https://console.developers.google.com/apis/api/compute
// 2. This sample uses Application Default Credentials for authentication.
// If not already done, install the gcloud CLI from
// https://cloud.google.com/sdk and run
// `gcloud beta auth application-default login`.
// For more information, see
// https://developers.google.com/identity/protocols/application-default-credentials
// 3. Install the Node.js client library by running
// `npm install googleapis --save`
const {google} = require('googleapis');
var compute = google.compute('beta');
authorize(function(authClient) {
var request = {
// Project ID for this request.
project: 'my-project', // TODO: Update placeholder value.
// The name of the zone for this request.
zone: 'my-zone', // TODO: Update placeholder value.
// Name of the instance resource to resume.
instance: 'my-instance', // TODO: Update placeholder value.
resource: {
// TODO: Add desired properties to the request body.
},
auth: authClient,
};
exports.resumeInstancePubSub = async (event, context, callback) => {
try {
const payload = _validatePayload(
JSON.parse(Buffer.from(event.data, 'base64').toString())
);
const options = {filter: `labels.${payload.label}`};
const [vms] = await compute.getVMs(options);
await Promise.all(
vms.map(async (instance) => {
if (payload.zone === instance.zone.id) {
const [operation] = await compute
.zone(payload.zone)
.vm(instance.name)
.resume();
// Operation pending
return operation.promise();
}
})
);
// Operation complete. Instance successfully started.
const message = `Successfully started instance(s)`;
console.log(message);
callback(null, message);
} catch (err) {
console.log(err);
callback(err);
}
};
compute.instances.resume(request, function(err, response) {
if (err) {
console.error(err);
return;
}
// TODO: Change code below to process the `response` object:
console.log(JSON.stringify(response, null, 2));
});
});
function authorize(callback) {
google.auth.getClient({
scopes: ['https://www.googleapis.com/auth/cloud-platform']
}).then(client => {
callback(client);
}).catch(err => {
console.error('authentication failed: ', err);
});
}
Here and here is the documetation for the new beta verison of the api. You can see that you can suspend an instance like:
compute.instances.suspend(request, function(err, response) {
if (err) {
console.error(err);
return;
}
And you can resume a instance in a similar way:
compute.instances.resume(request, function(err, response) {
if (err) {
console.error(err);
return;
}
GCP recently added "create schedule" feature to start and stop the VM instances based on the configured schedule.
More details can be found at
https://cloud.google.com/compute/docs/instances/schedule-instance-start-stop#managing_instance_schedules

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

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

AWS CodeCommit commit message to Hipchat

I want to send AWS CodeCommit commit message to a HipChat room. I already have a lambda function which gets triggered for a particular commit. What I need is to get commit detail messages from CodeCommit. Commit ID, commit message, branch name etc.
Inside lambda you can require sdk then get parameters from lambda event.
const AWS = require('aws-sdk')
let codecommit = new AWS.CodeCommit();
var params = {
commitId: 'STRING_VALUE', /* required */
repositoryName: 'STRING_VALUE' /* required */
};
codecommit.getCommit(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
Depending on the info you get in lambda event parameters you can call one of those methods from sdk.
https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CodeCommit.html

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.