Create a conversation

hello guys, I have the following use case:

I’m sending a proactive whatsapp message to welcome new customers, so I need to perform the following actions by api:

  • Create User
  • Create a conversation with the context of the proactive message sent! * when creating this conversation seto the whatsapp channel

The problem is the following when the user responds to proactive a new conversation is generated, so I have a duplicate conversation on the same channel and without context, could you help me?

@Raviraj Would you help me?

Hi @Marllon_Mainardes,

  1. When is the step #2 happens?
  2. How’s the message sent to Whatsapp? Is Outbound messages API being used?
  3. How’s the conversation is created when user responds to the Whatsapp message?
  4. What is the expected behavior?

If any of the APIs provide these tasks out-of-the-box, could you please share the link to it for the context?

1 Like

Hi, Raviraj!

Let me explain better:

I’m using Outbound Messages API to send Whatsapp proactive messages. I’m doing it on a frontend Freschat custom APP.

When I send, I keep the log of the message as a private note on the conversation.

When the number is not a User yet on Freshchat, then I create a new User (using the API) and I create a new conversation (using the API) on the WhatsApp channel, so I put the log on it.

The problem is: when this new User replies, a new User/Conversation is created in Freschat.

The expected behavior would be that the User’s replie to be created on the conversation I created.

1 Like

Hi @Marllon_Mainardes,

The workflow you have mentioned is the expected behaviour.

The Freshchat Outbound Messages API is just a wrapper for the Whatsapp Proactive Message API, so Freshchat will simply forward the payload to Whatsapp’s services.

And when some one starts a chat, since the data is being retrieved via the Whatsapp service a new user is created, and the thread is always maintained for that number(unless the number is deleted via GDPR settings on Freshchat).

However, for your use case I would recommend trying out the workflow provided below.

  • Trigger the Outbound Message API.
  • Use Freshchat’s User Query API to search for a contact on Freshchat.

1. When the end user has already started a chat via Whatsapp

  • If the user exists, search for the conversation based on the user id retrieved in the last step using the API in the link here.
  • If there are multiple conversations, check if channel_id is of Whatsapp.
  • If channel_id matches Whatsapp, retrieve the conversation id, and add a private note with the details that you seem relevant for your use case such as the message or template etc.

2. When the end user has not started a chat via Whatsapp

  • Store the template or message details in the marketplace using the persistent storage option. I’d recommend the unique namespace since it will always be unique. So the data will be stored with the phone number as the identifier as shown below.
client.db.set( "+9195845847854", { "namespaceId": "0ac511a8-1628-4306-a1cb-ad00d39f9ae5" }).then(function(data) {
  // success operation
  // "data" value is { "Created" : true }
},function(error) {
  // failure operation
  • Listen for OnConversationCreate event using the product events.
  • Retrieve the Conversation ID and Channel ID
  • Check if the Topic is Whatsapp by retrieving the channel_id from the product event payload.
  • Use the end user’s phone number to search for data stored in the Marketplace persistent storage.
  • If data is present, the add a private note with the necessary details you seem relevant for your use case.

The step #2 of the app will cover all new users, while step #1 will cover all existing users there by maintaining context for agents on the Freshchat conversations.

For better clarity, I have a designed a workflow in the link here.

Hope this helps.

1 Like

Hi, Arjun!

I guess this would not work for my expected behaviour.

Let me talk first about when user already exist:
Currently when the conversation selected is already from whatsapp, I don’t need to run this search for the User, I just get the conversation id from SDK. I know if it is a WhatsApp conversation, calling the API for conversation and validating the channel_id.
When the selected conversation is not from WhatsApp, I’m making this search for the user, but there’s a problem: The User/Conversations API returns an array with only the conversation_id, so for each item, I need to call Conversation API to check the channel_id. For what I could see on our customers, It’s very common that they have multiple Users with the same phone number or email, something like 30 Users. So sometimes this search process takes more than 50 API requests in one minute, and this is not allowed in the SDK.

Now about when user does not exist:
I have already considered this workaround, but there’s an issue:
Here on Brazil, sometime ago, all phone numbers have been increased with a new digit: 9. And I verified that I can send a message with this 9 digit or not. WhatsApp API will understand and deliver the message. So when Users replies, it may not match what I have stored. And here I’m just talking about Brazil. I suspect that this have happend in others countrys as well.

The other thing that I forgot to mentionate early is that I’m allowing the customer to configure if he wants to keep a log as private note or reopen the conversation and send a public message. I’m doing it because some customers has Freshbots, and when they send a proactive message, they don’t want that the bot gets triggered when user replies. So reopening te conversation and keeping the log as public prevents it.

Got it @Marllon_Mainardes.

Thanks for explaining this in detail. I do believe that this will need some dev effort from Freshchat.
Atleast allowing the user_id to be populated in the conversation details.

Although the ideal approach is to natively(Freshchat feature) first create the user, start the conversation on Freshchat first before passing the data to Whatsapp API. Then on reply, retrieve user via search natively to append it to the chat but this is something we don’t have yet.

I will try to explore alternative solutions for your scenario here, and I will also pass on this use case to our Freshchat Product team, and will keep you updated. But I cannot commit on this since I am not sure if they will take this up since it may involve some significant changes on our backend architecture.

Hope you understand.

1 Like

I understand Arjun, I still thank you for your help!

1 Like