Hi! I was able to add 2 CTA buttons to our chatbot with the JS+CSS code below. The code includes sizing, padding, alignment, and responsive layout. (note: I have coded specific sizing and padding to my chatbot, so you will need to customize the code). Feel free to reach out for help with yours.
At the moment, I decided to remove the CTA buttons. I was running into problems with overlap when the AI Chatbot produced longer responses, particularly on mobile. I am working on code to 1) inject the CTA buttons after a user sends 1 message (prior to this, the CTA buttons were interfering with the pre-select options we use); 2) inject the CTA buttons as separate message containers with proper spacing to avoid overlap
The code I posted does work though and may help others with similar needs.
Thank you. I already use waitForElement to change all links that would normally open in a new tab/window to instead open in the same tab/window, so the code your Devs provided wonât work for me (my code is below).
Max, Iâm struggling to find a way to inject the CTA buttons with the following requirements:
only display after the User sends 1 message
display naturally in the flow of conversation
my original code has them fixed at the bottom of the message container, which causes a problem when the AI Assistant sends longer answers, particularly on mobile.
first display after the Assistantâs 2nd message and continue to display after each Assistantâs message after that
we include 5 pre-select boxes for the user at the start of the chatbot conversation
CTA button feature continue to work after User closes and reopens the chatbot
Iâve tried vibe coding this on Claude multiple times wth no luck, so if this is something your team can help accomplish, it would be much appreciated.
Ideally the CTA buttons would be placed in their own transparent container after each AI Assistantâs message (starting after the Assistantâs 2nd message; n=2 to infinity), in order to maintain the conversationâs flow; similar to the picture in my original post, but placed relative to the Assistantâs response to remove the space that is created in my original code when the CTA buttons are in a fixed position at the bottom of the conversation container.
Iâve double-checked your code, tested it in your and my test widget, and it didnât work, unfortunately. Could you please double-check it and let me know if it works on your end?
I am not sure which code youâre referring to. The code in my original post does not accomplsh the specifications Iâm hoping for. The code in message 4/8 is code for a different purpose, but it includes waitForElement so the code your Devs provided in messaagge 3/8 doesnât work for my widget.
Anyway, Iâll discuss with the devs if we can build a new script that meets all your conditions and, most importantly, runs reliably.
Just a couple of questions before I pass your request to the devs:
Once the assistant sends the 3rd message, should the button move under the 3rd message or they should be kept below the 2nd message?
Youâve mentioned 2 conditions:
display after the User sends 1 message
first display after the Assistantâs 2nd message
Since the assistantâs first response corresponds to the userâs first message, does that mean the buttons should actually appear only after the user sends their second message â when the assistant has just sent his second message?
Understood. I was not the person to enter that code but my understanding is that it changes all links that would normally open in a new tab/window to instead open in the same tab/window.
To answer your other questions:
Ideally, the CTA buttons would continue to move down under the 3rd message, then 4th, then 5th, etc., only appearing once at any given time.
I would like the CTA buttons to appear after each Assistantâs written response to the Customer user. In the example below, the User has selected the option âIâm looking for a puppyâ from the pre-select choices. I would still like the CTA buttons to appear after the Assistantâs message, âThatâs great! Do you have a specific breed in mindâŚâ
Hi Max, thanks for this. It works great and the solution is fixed.
Note: We already declared âconst waitForElementâ in JS code to keep users on the same tab when clicking a link inside the chatbot (I included this code in my original post).
With the help of Claude AI, I was able to find a workaround to maintain the same-tab function with the CTA buttons injected. Iâve shared it below for future reference: