Injecting a message into live chat

I wrote a workflow to watch for stale live chats, closing them if they are stale for too long, and now I’m trying to figure out how to inject a message (e.g., “Are you still there?”, “I’m closing this chat. Please follow up if you would like further assistance.”)

I’m defining a message and posting it per how I understand the docs for the conversations API, which I believe is what I should use but I’m getting a 500 error. It makes me wonder if the API really allows for injecting messages into live chats.

 message = {
 "type": "MESSAGE",
 "text": "Can I help you with any further questions?",
 "senderActorId": "A-[ACTORID]",
 "recipients": [
 {
 "deliveryIdentifier": {
 "type": "CHANNEL_SPECIFIC_OPAQUE_ID",
 "value": "[ID Taken from live chat conversation]",
 "recipientField": "TO"
 }
 }
 ],
 "channelId": channel_id,
 "channelAccountId": channel_account_id
 }

 message_string = json.dumps(message,indent=4)

 url2 = "https://api.hubapi.com/conversations/v3/conversations/threads/" + conversation_id + "/messages"

 response = requests.post(url=url2,headers=headers,data=message_string)

I’m able to send a message to a conversation that’s not a live chat (i.e., that’s email using the above template) but I can’t get the message into a live chat.
I would appreciate any pointers!

Hi @JasonK1,
Thank you for posting to the Community!
I’d like to tag in some of our Top Contributors to take a look here!
Hi @HubSpot_Corey @Bortami and @WesQ Do you all have any tips for @JasonK1 on the above?
Thank you!
Cassie, Community Manager

We figured this out. There was just a problem with the ‘recipients’. The ‘actorId’ was missing.

We ended up grabbing the ‘recipients’ information from the WELCOME_MESSAGE that came back in the message history (a GET request to conversations/v3/conversations/threads/{threadId}/messages).