I have created a Vertex AI chat agent and embedded it into the NextJS app using the conversation messenger. Below is the code snippet.
<df-messenger
location="xxxxxxx"
project-id="xxxxxxxxxxxx"
agent-id="xxxxxxxxxxxx"
language-code="en"
max-query-length="-1"
>
<df-messenger-chat-bubble chat-title="xxxxxxxxx"></df-messenger-chat-bubble>
</df-messenger>
My NextJS app has login flow in place, and now I want to send the authToken from my chat agent (FE) to vertex ai playbook and which I am unable to do so.
Things I had have tried
1. Setting session-params
const sessionParams = {
name: 'john doe',
authToken: '111111111111111',
userId: 'user_12345',
};
dfMessenger.setAttribute('session-params', JSON.stringify(sessionParams));
However, I am unable to read this value on the vertex ai playbook instructions .I tried using $session.params.name , $session.params.authToken and they are blank
2. I also tried updating the payload of the network request that gets sent from FE to BE (vertex ai agent in this case). Here is the code snippet
dfMessenger.addEventListener('df-request-sent', function(event) {
event.detail.data.requestBody = {
...event.detail.data.requestBody,
custom: {
authToken: 'xxxxxxxxxxxxxxx',
}
};
});
On the network call, I could see my custom payload gets added to the request body. However, I am unable to read the request body on the cloud.
On the playbook, I am routing the first interaction to TOOLs where I am invoking a cloud function to read the request, but it's failing to get the custom fields added on the request body.
@functions_framework.http
def process_requset_body_details(request):
request_json = request.get_json()
request_json is also blank for me
Am I missing something here or is there an alternative approach to do this ?