I have a node js application where the conversation ID of a web chat is posted. I can see in the console that the conversation ID is generated. But when I run
var currentConversationMessages=conversationsApi.getConversationsChatMessages(conversationId);
The currentConversationMessages is empty even though I can see text being posted in the chat.
Hello,
The screenshot you have posted is about a different endpoint/request.
getConversationsChats - GET /api/v2/conversations/chats is meant to Get active chat conversations for the logged in user
.
If you are invoking this endpoint with an access/bearer token that is not associated with the user having these chats connected, it will return 0 (i.e. if your server uses an OAuth Client Credentials Grant flow to obtain a token, this will not return any chats).
Now, regarding getConversationsChatMessages - GET /api/v2/conversations/chats/{conversationId}/messages, it also depends on who is invoking this endpoint and at what stage of the flow.
By who I mean: access/bearer token associated with the user involved in the chat (Implicit Grant flow, Authorization Code flow, SAML2 Bearer Grant flow), or someone/something else (e.g. OAuth Client Credentials Grant flow).
If the token is the one of your user, the query should bring back the messages.
If the token is a Client Credentials Grant one, the outcome of the request will depend on if the chat is active (API endpoint returns 403 error - not a participant in the chat) or ended (API endpoint returns messages from this chat session).
Regards,
Thanks for the response. I am using for OAuth ,Client Credentials (client id and client secret). How do I associate a User with an OAuth? Does the OAuth have to have the same name of a user? Please send any code samples.
Tokens "associated" with a user are the ones obtained through an OAuth Implicit Grant flow, Authorization Code Grant flow (or SAML2 Bearer Grant flow).
You would have to create the corresponding OAuth client in your Genesys Cloud configuration, and follow the steps of the corresponding OAuth flow to obtain a token.
Such flows imply that the user will, at some stage, provide his/her username and credentials on the Genesys Cloud Login page.
If your idea is to have a server application act on behalf of the user, without having the user login/authenticate, then, it won't be possible.
Again, if your goal is to have a server application, sending Platform API requests on behalf of a user, the proper OAuth Grant type could possibly be Authorization Code Grant. A user (through his Web client) logs in/authenticate, and is redirected to your server (passing code to the server). The server retrieves the code and requests a token from Genesys Cloud. The server can maintain that token and can use it to perform actions on behalf of the user.
Regards,
I have set up a Token Implicit Grant (Browser) OAuth in Genesys. I have been following
this site
I am getting the following error
What should I set the redirect URL to?
Implicit Grant would be for a client-side webapp approach.
I mean a web client (Chrome, Firefox), accessing a url to get html/javascript running at browser level.
If that's what you are now trying to do, and if you are not too familiar with OAuth Authorization flows, I would suggest to take a look at this blueprint: Build a chat translation assistant with the AWS Translate service
This blueprint explains the configuration steps (Creating an OAuth Client) and provides a sample code for a client-side interaction widget (webapp).
You'll still need to adapt the code to your needs - but you can reuse the explanations on creating an OAuth Client and the part that manages the authorization in the webapp sample code (it leverages our Platform API Javascript SDK).
The sample code contains a nodejs/express script to server this webapp via a local webserver.
Regards,
Thanks for the reply and got it working, now i need to pass the token from the web page to the node js web app.
You're not supposed to do this.
If by node js web app, you mean having your nodejs script performing the requests, then passing the token from the webclient to the server is not an approved secure way of doing this.
As I said, if you need a server to act on behalf of your user, implement and Authorization Code Grant (Code Authorization) flow.
Regards,
This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.