Programatically add context to chat so AI assistant can use with API calls

Hello,

TL;DR — Can the AI assistant read visitor attributes and use their values as parameters in its API calls?


What i want to achieve: set attributes on user login…

Tawk_API.setAttributes({ chat_token: 'abc123...' });

…and then have the AI assistant pull chat_token from the attributes when it calls my API.

Flow on my website:

  • When a user logs in on my site, I show a randomly generated hash string to them in the profile page, named “chat_token”, which is unique for each user.
  • When they begin the chat, they can get info about my page and they can also execute some actions (get info about their details, cancel payment, etc).
  • In order to execute these actions, I have set up the AI assistant to always prompt them for their chat_token.
  • The user is instructed to go to their profile page, copy the token and paste it to the chat.
  • After pasting it to the chat, the AI assistant will execute the appropriate request to my API endpoints.
  • The AI assistant chat bot will use the provided chat_token to authenticate the user and successfully execute actions using the provided OpenAPI spec.

I want to automate this. It is tedious for the user to have to copy-paste the chat token each time they log in. How can I automatically add context to the chat when a user logs in on my site?

  • I have tried using setAttributes (developer.tawk.to/jsapi/#setAttributes), didn’t work.
  • I have tried adding events (developer.tawk.to/jsapi/#addEvent) and seeing if the AI assistant would use the provided chat token in the API calls, it didn’t.

I have setup a schema.json endpoint, as instructed in the Integration/API page of the AI assistant.

Best regards,
Matjaž

1 Like

I posted this 9 months ago. Bump
@kristaps