I’ve integrated the SendBird AI Chatbot into my Laravel application (with a JS script). When users inquire about their orders (e.g., “Where is my order?”), I’ve set up a function that requests order details from our server via an API. However, I need to send the current authenticated user’s Bearer token in the request headers to properly identify the user.
Does anyone know how I can retrieve the authenticated user’s Bearer token from the website without asking them for any additional information? Any help would be appreciated!
Apologizes for the delay in response. Feel free to raise up a ticket as well if you have more advanced queries on Function Call. We are interested to see how you proceed with Function Calling.
I understand you’re looking to retrieve the authenticated user’s Bearer token without asking them for extra information, to provide personalized order details through your SendBird AI Chatbot integrated into your Laravel application.
Since SendBird doesn’t currently support storing dynamic Bearer tokens, here’s a workaround you might consider:
When a user logs into your application, you can generate a unique user in SendBird using Platform APIs. While creating this SendBird user, include metadata that contains your application’s user ID (UID) or any identifier that links back to your user system.
Now, when the user interacts with the chatbot and asks, “Where is my order?”, the chatbot triggers a function call. This function call can pass along the user_id or the metadata you added earlier. With this information, your server can recognize which user is making the request.
Since you have the user_id, you can use it on your server to look up the corresponding Bearer token you’ve securely stored for that user. This allows you to include the Bearer token in the request headers when querying your API for the order details, without needing to ask the user for it again.
By implementing this processing logic in your proxy or backend, you can securely obtain the necessary Bearer token and provide personalized order information seamlessly. This approach maintains security and enhances the user experience by keeping everything behind the scenes.
I hope this helps! If you have any more questions or need further clarification, feel free to ask.