How to get message from agent ( in aws connect ) to serverless lambda - amazon-web-services

My intention is to build a chatbot thru aws lex and optionally communicate with agent in aws connect.
For this I have created a custom chatbot widget which connects to api gateway and forwards message to lex thru websocket and respond back to chatbot widget. I also redirect these message to agent rather than lex in cases where customer whats to chat with agent.
Im able to send message from lamda to agent, but I am having trouble receiving message back from agent. How can solve this ?

Related

System design : AWS chat application with API Gateway / SQS - how does server send message to recipient?

This is a system design question about creating a messaging application (like WhatsApp or FB messenger).
I saw a video that had the users connected via websocket to the API Gateway , then API GW pushed the message onto SQS - which was then polled by the EC2 compute layer to process the message (store it in the db) and hopefully send the message back to recipient.
How can the backend ec2 / compute layer send the message to the recipient (Bob) ? Can it just call a route on the API Gateway and it would know the connection details of the recipient and where to send? Would there need to be an additional caching layer to store info about the connection details of every user? I'm newer to AWS so not sure how this is accomplished and whether you can call API GW to send back to a user.
Also if you know how group chat would work please share.
As mentioned in the documentation, your backend EC2 servers can send messages to the connected clients directly via the #connections API. This documentation page walks you through how to do that.
For this, you'll need to add the connectionId to the header. See this answer on how to do so.

How to configure AWS Chatbot to deliver useful messages from Beanstalk to Slack?

We have an Elastic Beanstalk deployment and wanted to receive events into our Slack channel. We setup EventBridge and Chatbot to deliver notifications. Everything works, except the notifications are useless, because Chatbot does not map the message detail only the detail type, which does not tell much. See the attached image of a notification (cropped to cut out the region/account info), the message is not too useful without telling us what was the actual change, which is in the event received by EventBridge and sent to SNS, but not mapped by Chatbot when sending to Slack.
Even their example test notification demonstrates the same problem:
I checked the Chatbot documentation where they claim support for multiple services via EventBridge. I checked EventBridge documentation where they list Elastic Beanstalk among supported services.
I also subscribed and tested Health service notifications, which work just fine. See the example test notification below.
I could not find a way to configure Chatbot to do the right thing. I could write my own message transformer for certain events and call a Slack webhook instead of using Chatbot, but I wanted to avoid writing custom code here for now.
Does anyone know if it is possible to fix Beanstalk notifications that are sent from EventBridge to Chatbot then to Slack? Or is AWS working on supporting more service notifications and in the future this might start working as it should?
Thank you in advance.

Integrate aws websocket api with springboot application

**I have created realtime activities website.
currently my website is like this:
frontend page created websocket with endpoint url wss://xyz.com/chat/$scope.userId
In my backend i store a map table of userId-Websocketconnection
when anyone likes image of userId-5 , backend sends notification to websocketConnection whose userId is 5
But now i want to use Aws websocket api
i am confused at several points
how to send userId with websocket connection request to aws websocket api
using aws websocket api ,how can i store this connectionid and user id in my springboot database
when someone likes image of userId-5 , how will i send notification to websocket connection of userId-5
Is it possible using aws websocket api. Please help me
**
That's what exactly APIGateway websocket protocol offers.
You need to connect to websocket, then send a message (json) which has userid in it. Example message below.
{"action": "SUBSCRIBE","payload": {"userId":"123"}}
On APIGateway you can create SUBSCIRBE route and map it to backend endpoint as Integration request where you store connection id into database.
https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-websocket-api-integration-requests.html
Whenever your spring boot application wants to push notifications, you can make use of AmazonApiGatewayManagementApi and broadcast the message.
https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-how-to-call-websocket-api-connections.html

Difference between a device subscribing to an SNS topic, and a lambda function subscribing to a topic?

Im currently trying to design a scalable push notification service, which can send notifications to 5-10 mil users in a very short time. I came across two AWS related architectures which got me confused.
Use case: Send a notification to all the users.
1) Each device subscribes to an SNS topic, and if we want to send a push to all users, we just publish to the topics endpoint. And SNS handles the rest(sending to the million users)
2) Lambda functions are subscribed to SNS topics. We send a message to an SNS topic containing all the device tokens/batches, and then lambda calls APN/Firebase endpoints.
I fail to see in what case the second architecture would be beneficial compared to the first?
Mobile push notification :
sns endpoint will created based on user device token and you will get device token from Adm,Fcm,etc like push notification platform sdk and you can trigger push notification to perticular user based sns endpoint because each device have different endpoint and it created user device token and you will have track user device token and endpoint and userId and you can able to see aws sns mobile push notification console
1) you can create manually also
2) you can create endpoint using programmatically
you can refer below sdks to create via code https://docs.aws.amazon.com/sns/latest/dg/mobile-push-api.html
Lamda push notification
You can create sns topic in sns console and you can subscribe which lambda you want deliver notification
basically if you want connect one lamda to another lamda you can use those case
example 1:
you have micro service for sending otp to user and micro service deployed in different lambda and application recives sending otp request your application main lamda and now you need call otpservice lamda so you can create one sns topic and under subscription you can subscripe otp micro service lamda so main lamda will trigger otp service sns endpoint it will deliver notification micro service lamda

How to send notifications to a specific user with AWS SNS?

I am developing an app like Dominoes. In which, I would like to send a Push notification to the Customer, when his/her Order is prepared.
I had been using OneSignal to do so (through sending notification to a particular player id), and now we would like to do it with AWS SNS Service, as we are using bunch of different AWS Services too.
We don't want any marketing/bulk push notifications, the SNS Service would do only one thing - send a particular message from the Restaurants' Mobile (using REST API), and it would reach the Customer's mobile.
With OneSignal, we used to give the PlayerID/UserID of the receiver. Does this method apply to AWS SNS too? Also, we could only work with HTTPS POST requests in our platform.
Any help is appreciated :)
Thanks!