How to add and remove a user from multiple Call Queues at a time using RingCentral? - ringcentral

I have multiple RingCentral Call Queues and I want to build an app that allows users add and remove themselves from a set of pre-configured queues. This is a mobile app that users will use and set their queue availability based on their physical location in a store, with each queue corresponding to a department so users can change the queues themselves as they move between departments.
Given a list of Call Queues, I can update each queue at a time using the following API:
Assign Multiple Call Queue Members API
POST /restapi/v1.0/account/{accountId}/call-queues/{groupId}/bulk-assign
However, this can be a bit inefficient as updating each user may result in one API call per queue.
Is there a way to add/remove a user from multiple queues with one API call?

The following API can be used. This adds and removes the user as a queue member.
Join/Leave Call Queue API
The following API will set a full use queue membership for all queues. The user will be a member of all queues listed and not a member for any queue not listed.
PUT /restapi/v1.0/account/{accountId}/extension/{extensionId}/call-queues
{
"records": [
{"id":"11111111"},
{"id":"22222222"}
]
}
The response will look something like the following:
{
"records": [ {
"id": "12345678",
"name": "Bakery"
}, {
"id": "87654321",
"name": "Cafe"
} ]
}

Related

AWS Step Function Synchronous Task Token

I have a use case which I want to use Step Functions to solve but I can't find a way to solve this problem. Your help would be greatly appreciated.
The problem goes like this: I have an Amazon API Gateway which has a /start endpoint. a POST to this endpoint should start a data processing session and return a URL to an app which the API client can use to capture some data. Once data capture is complete, some processing takes place before the final response is sent to the API client via a callback.
My thinking, as you can see below, is to generate a task token and send it to the Data Capture Service. Then, when the user data capture is complete, the service can send a request to the Step Function API to say that stage is complete. The problem with this is how can I return the URL to the client from within the Step Function? I don't want to use a callback to do this.
One option is to create the data capture session within the 'Step Function Initiator' Lambda but then how do I provide the Data Capture Service with a task token?
Really, what I need is some mechanism of synchronously returning something (either a URL from that call or the task token from the first stage) from within the Step Function to the Lambda which started the execution. Is this possible? How would you solve this?
In step function initiator lambda, you must be doing start-execution which returns an executionArn
Next, you can loop and call get-execution-history api and task token will be part of the 'capture data' task parameters. Since this is the first step, this really should be done with in couple of seconds, so, we can keep running this loop every second until desired step in step function is initiated and task token can be obtained.
Take this example, i am passing the task token to another step function call from current step function.
{
"StartAt":"ChildTask",
"States":{
"ChildTask":{
"End":true,
"Type":"Task",
"Resource":"arn:aws:states:::states:startExecution.waitForTaskToken",
"Parameters":{
"Input":{
"token.$":"$$.Task.Token",
"foo":"bar"
},
"StateMachineArn":"arn:aws:states:us-east-1:110011001100:stateMachine:ChildStateMachine",
"Name":"MyExecutionName"
}
}
}
}
Get Execution history:
aws stepfunctions get-execution-history --execution-arn arn:aws:states:us-east-1:110011001100:execution:ParentStateMachine:667102b3-b19c-b7ab-b119-9ec6cf23e505
Result:
one of the first few entries in execution history and task token is part of the parameters. we can exit the loop, grab that, send it back to Api Gateway.
{
"timestamp": "2021-03-12T13:56:58.097000-05:00",
"type": "TaskScheduled",
"id": 3,
"previousEventId": 2,
"taskScheduledEventDetails": {
"resourceType": "states",
"resource": "startExecution.waitForTaskToken",
"region": "us-east-1",
"parameters": "{\"Input\":{\"foo\":\"bar\",\"token\":\"o6QVQ9gls.......=\"},\"StateMachineArn\":\"arn:aws:states:us-east-1:110011001100:stateMachine:ChildStateMachine\",\"Name\":\"MyExecutionName\"}"
}
}

How can I use TTL to prevent a message backlog when using Firebase Cloud Messaging with Django-Push-Notifications?

I am working with Firebase Cloud Messaging in Django using django-push-notifications to deliver push notifications to our users via desktop notifications.
After a browser is fully closed (such as when the the computer is turned off), our users receive a backlog of all notifications previously sent next time they boot up.
While there are situations where a user would want to receive the entire backlog of messages, this is not one of them.
It seems the answer is to set TTL=0, as per this section of the FCM documentation, but my attempts are not resulting in the desired behavior.
Please help me better understand TTL in this context. If TTL is the right way to go, what is the proper way to format TTL in send_message() using django-push-notifications so that messages will not accumulate if not immediately delivered?
Here is what I have attempted:
devices.send_message(
body,
TTL=0,
time_to_live=0,
link='blah',
extra={'title': 'blah blah', 'icon': '/foo/bar.png'}
)
The format that you send seems different from the one in the documentation you linked. From the documentation:
{
"message":{
"token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
"data":{
"Nick" : "Mario",
"body" : "great match!",
"Room" : "PortugalVSDenmark"
},
"apns":{
"headers":{
"apns-expiration":"1604750400"
}
},
"android":{
"ttl":"4500s"
},
"webpush":{
"headers":{
"TTL":"4500"
}
}
}
}
So key here is that the time-to-live for a webpush message is set under webpush/headers/TTL, while you're adding it to the top-level.

How to get RingCentral Call Queue Members Availability?

How can I get the Call Queue availability for queue members per queue which is shown in the Online Account Portal? I specifically want the Available, Busy and Unavailable statuses shown in the UI under "Members Availability" per queue.
I've found a few Call Queue APIs that can list queues and queue members but they provide member availability like the UI.
Call Queue APIs:
Get Call Queues API
Get Call Queue Members API
The image below is from the article on Call Queue - User Availability and Call Handling
The above is on the right track. Once the list of queue members is available, you can query each user for his or her queue availability.
Note: A user's queue availability as presented below is the same for all queues they are present on so to do a presentation by queue, this information needs to be combined with their queue membership list. This can be retrieved from the queue or user perspective:
Call Queue Members
User's Queue List
To manage individual queue availability, add/remove the user from the queues of interest which can be done using the Edit Call Queue Members API.
For both steps query the Get User Status API. An example is provided below.
Get User Status API:
https://developer.ringcentral.com/api-reference#Presence-getPresenceStatus
An example request and response looks like the following:
Request:
GET /restapi/v1.0/account/{accountId}/extension/{extensionId}/presence
Response:
HTTP 200 OK
{
"uri": "https://platform.ringcentral.com/restapi/v1.0/account/403228676008/extension/403228676008/presence",
"extension": {
"uri": "https://platform.ringcentral.com/restapi/v1.0/account/403228676008/extension/403228676008",
"id": 403228676008,
"extensionNumber": "101"
},
"presenceStatus": "Available",
"telephonyStatus": "NoCall",
"userStatus": "Available",
"dndStatus": "TakeAllCalls",
"allowSeeMyPresence": true,
"ringOnMonitoredCall": false,
"pickUpCallsOnHold": true
}
Use the following to get the user's queue availability:
1) User Queue Setting
The user's Do Not Disturb dndStatus property is used for indicating whether the user is accepting or not accepting calls, including for call queues. The user can set their dndStatus to be one of the four following values where "Department" is another name for Call Queue:
DoNotAcceptAnyCalls
DoNotAcceptDepartmentCalls
TakeAllCalls
TakeDepartmentCallsOnly
This can roughly be mapped to:
Unavailable for Queue Calls: DoNotAcceptAnyCalls or DoNotAcceptDepartmentCalls
Available for Queue Calls: TakeAllCalls or TakeDepartmentCallsOnly
2) User Overall Availability
The next step is to check the presenceStatus property which is an enumerated string with the following values: Offline, Busy, Available. Offline maps to Unavailable in the UI. This is an overall availability for both personal calls and queue calls.
3) Queue Member Availability
To create the queue member availability, combine the two properties above like the following pseudocode.
I added an extra "Available" condition below which is strictly not needed, but useful for explanation:
member_availability =
user.dndStatus == "DoNotAcceptAnyCalls" ? "Unavailable" :
user.dndStatus == "DoNotAcceptDepartmentCalls" ? "Unavailable" :
user.presenceStatus == "Offline" ? "Unavailable" :
user.presenceStatus == "Busy" ? "Busy" :
user.presenceStatus == "Available" ? "Available" : "Available"
This gives the user's availability for all queues they are on so this needs to be mapped to either a queue members list or the user's list of queues.
List Call Queue Members API
User Info API's departments property
Example Code
Here's some Ruby wrapper code I wrote to make it easier to update the user's queue status here:
RingCentral Ruby SDK extension_presence.rb

Cognito User Migration Trigger - Exception during user migration - Exception Location

We're using a lambda function to respond to the 'User Migration' trigger in AWS Cognito. When something like a syntax error occurs, you can see it in cloud watch logs. However, "Exception during user migration" errors seen on the login page are no where to be found in the cloud watch logs.
Where are we supposed to look for these? I can't find any anything in the documentation and assumed it would have gone to cloud watch.
I can't test it in the lambda interface because one of the parameters being passed into the lambda function will have a function nested within the object and I can't create a test JSON setup that has that. There's also no test trigger for user migration that is pre-built.
Any ideas as to why I can't see this in cloud watch or where the exceptions would be shown would be greatly appreciated.
Unfortunately Cogntio doesn't expose any logs (or metrics, for that matter!).
The closest you can get is to view the lambda's logs in CloudWatch. If you log your response, and watch your lambda's error metric then you should mostly be able to debug issues internal to the lambda.
This does leave a few edge cases:
You won't see anything if the lambda can't be invoked (this would only happen under heavy concurrent loads either on that single lambda, or on all lambdas across your account)
If you return a bad response the lambda will succeed but the trigger action will fail and Cognito will give you a fairly generic message. At this point you're at the mercy of AWS' documentation to work out what's wrong (which can be a bit hit and miss- although StackOverflow always helps!).
You can find an example payload for the lambda in the trigger documentation:
{
"userName": "THE USERNAME",
"request": {
"password": "THE PASSWORD"
},
"response": {
// it is your responsibility to fill this bit in and return the completed object back:
"userAttributes": {
"string": "string",
...
},
"finalUserStatus": "string",
"messageAction": "string",
"desiredDeliveryMediums": [ "string", ... ],
"forceAliasCreation": boolean
}
}
n.b. As an aside, which you might know, but Lambda payloads always have to be in JSON, which does not store functions. So you should always be able to derive a test payload to use in the console.

AWS Lambda for Client to Client Push Notifications

Thanks to this community I've learned that is possible to send AWS SNS Push notifications via Lambda with node.js (as a result of Parse migration). I am still struggling with the following:
Can this be done client to client x likes y's z. Where x is user 1, y is user 2 and z is the object being liked? If so, it seems like Cognito is not required that it can read directly from the database but is that accurate?
Does anyone have an example of how this was implemented?
Again, we don't want to broadcast to all users on a schedule but rather when a client performs an action.
Thanks so much in advance!
Let's say you have Device1 which creates a piece of content. That is distributed to a number of users. Device2 receives this content and "likes" it.
Assumption:
you have registered for push notifications on the device, and created a SNS endpoint on AWS. You have stored that endpoint ARN in your database, and associated it with either the Cognito Id, or the content Id. If your data is normalized, then you'd typically have the SNS endpoint associated with the device.
Your Lambda will need to have access to that data source and look up that SNS endpoint to send push notifications to. This will depend on what sort of data store you are using (RDS, DynamoDB, something else). What sort of access that is, and how you secure it is a whole other topic.
From your Lambda, you fetch the ARN to send the push notification to. If you pass in the content Id from the Like, and have the Cognito Id from the device that Liked it, you can then look up the information you need. You then construct a SNS payload (I'm assuming APNS in this example), then send it off to SNS.
var message = {
"default": "New Like!",
"APNS": {
"aps": {
"alert": "New Like!"
}
}
};
var deviceParams = {
Message: JSON.stringify(message),
Subject: "New Like",
TargetArn: targetArn,
MessageStructure: "json"
};
self.sns.publish(deviceParams, function (err) {
if (err) {
console.error("Error sending SNS: ", err);
}
});
It's not all done for you like it might be with Parse. You need to work a lot harder on AWS, but you have near unlimited power to do what you want.
If this is a bit too much, you may want to consider Google's newly updated Firebase platform. It's very Parse-like: https://firebase.google.com/
Hope that helps you move forward a bit.
Further reading:
http://docs.aws.amazon.com/sns/latest/dg/mobile-push-apns.html
https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/TheNotificationPayload.html
http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SNS.html