Passing values using Conversation API

DakogIkog
Member

When using your conversation API. And when loading the chat widget I wanted to pass the following values: 

 

1. Name

2. Email

3. Phone Number

4. An initial chat Message

 

From what I see in your conversation API I cant do any of these. Is it possible to do that using the conversation API? If yes, How?

0 Upvotes
8 Replies 8
cbarley
HubSpot Alumni

Hi @DakogIkog , if you know the identity of the customer visiting your site, you can pass those values to custom properties using the identify function. This information can be used in the chat widget. That said, a custom message would have to be built inside HubSpot, and can't be passed into the chat widget via the API.

0 Upvotes
DakogIkog
Member

Hi Connor,

 

I tried the identify function here is my code: 

 

var G_name = 'My Name';

var G_email = 'myemail@gmail.com';

var G_phone = '92849287423987';

var G_transcript = '';

 

function sendDetails(conversationID){
              var _hsq = window._hsq = window._hsq || [];

              console.log('NAME : ' + G_name);
              console.log('EMAIL : ' + G_email);
              console.log('PHONE : ' + G_phone);
              console.log('TRANSCRIPT : ' + G_transcript);

              _hsq.push(["identify",{
                           email: G_email,
                            conversation_id: conversationID,
                            name: G_name,
                            phone: G_phone,
                            transcript: G_transcript
              }]);
}
 
I call this function inside: 
 
window.HubSpotConversations.on('conversationStarted', payload => {
      sendDetails(payload.conversation.conversationId);
});
 
This info is not yet in my contact list... So I was expecting, according to identify documentation that it will be added automatically. But it is not there.
 
Which part did I go wrong?
0 Upvotes
PPipaliya
Member

In this example, We passing default property(like: email) right?

But How we can pass a custom object property?

Here custom object = testinfo and its property = testproperty

 

So, How to push or set value for custom object property?

 

 

 

0 Upvotes
DakogIkog
Member

Hi @cbarley 

 

Any updates on my inquiries? Please see above posting. I used the identify api but cant see any record added in the contacts.

0 Upvotes
rachelrc
HubSpot Employee

Testing on behalf of @DakogIkog 

 

Hi Connor,

 

I tried the identify function here is my code: 

 

var G_name = 'My Name';

var G_email = 'myemail@gmail.com';

var G_phone = '92849287423987';

var G_transcript = '';

 

function sendDetails(conversationID){
              var _hsq = window._hsq = window._hsq || [];

              console.log('NAME : ' + G_name);
              console.log('EMAIL : ' + G_email);
              console.log('PHONE : ' + G_phone);
              console.log('TRANSCRIPT : ' + G_transcript);

              _hsq.push(["identify",{
                           email: G_email,
                            conversation_id: conversationID,
                            name: G_name,
                            phone: G_phone,
                            transcript: G_transcript
              }]);
}

I call this function inside: 

window.HubSpotConversations.on('conversationStarted', payload => {
      sendDetails(payload.conversation.conversationId);
});

This info is not yet in my contact list... So I was expecting, according to identify documentation that it will be added automatically. But it is not there.

Which part did I go wrong?

0 Upvotes
rachelrc
HubSpot Employee

Testing on behalf of @DakogIkog 

 

Hi Connor,

 

I tried the identify function here is my code: 

 

 

var G_name = 'My Name';

var G_email = 'myemail@gmail.com';

var G_phone = '92849287423987';

var G_transcript = '';



function sendDetails(conversationID){
              var _hsq = window._hsq = window._hsq || [];

              console.log('NAME : ' + G_name);
              console.log('EMAIL : ' + G_email);
              console.log('PHONE : ' + G_phone);
              console.log('TRANSCRIPT : ' + G_transcript);

              _hsq.push(["identify",{
                           email: G_email,
                            conversation_id: conversationID,
                            name: G_name,
                            phone: G_phone,
                            transcript: G_transcript
              }]);
}

I call this function inside: 

window.HubSpotConversations.on('conversationStarted', payload => {
      sendDetails(payload.conversation.conversationId);
});

 

This info is not yet in my contact list... So I was expecting, according to identify documentation that it will be added automatically. But it is not there.

 

Which part did I go wrong?

0 Upvotes
cbarley
HubSpot Alumni

Hi @DakogIkog , sorry, I was sick on Friday so I wasn't able to troubleshoot this. I'll look into it today.

0 Upvotes
cbarley
HubSpot Alumni

hi @DakogIkog , do you have an example page I can look at? There could be error messages in the console. I have a feeling that the conversations widget likely hasn't loaded yet, and the function you're calling thus isn't firing when the action is completed. You may need use window.hsConversationsOnReady as explained in the docs (https://developers.hubspot.com/docs/methods/conversations_api/hubspot-conversations-javascript-api#h...😞

 

<script type="text/javascript">
  function onConversationsAPIReady() {
    console.log(`HubSpot Conversations API: ${window.HubSpotConversations}`);
  }

  /*
   If external API methods are already available, use them.
  */
  if (window.HubSpotConversations) {
    onConversationsAPIReady();
  } else {
    /*
      Otherwise, callbacks can be added to the hsConversationsOnReady on the window object.
      These callbacks will be called once the external API has been initialized.
    */
    window.hsConversationsOnReady = [onConversationsAPIReady];
  }
 </script>

One other note is that if you're using the identify function, that just stores the data in the tracker, but the data is not actually passed to HubSpot with this call.  The data will only be passed when tracking a pageview or an event (with either the trackPageView or trackEvent functions). I'd be sure to add that to your code as well.

0 Upvotes