Answer to a message

(Sergey) #1

Good day.

I must sent answer to the chat to hi message. This is how I do this:

function messengerReady() {

FxoMessenger.on(‘messageReceived’, function (message) {

 if (message.text == 'Hi') {

  FxoMessenger.sendMessage('Hi! Ask your question please');
  }

});

}

It works fine the first time.

But if:

  1. The user makes refresh.
  2. Opens the chat again.
  3. The chat shows all history including “Hi” and “Hi! Ask your question please”
  4. So, I catch messageReceived event with word Hi again and send “Hi! Ask your question please” the second time.

Is there way to detect that the second “Hi” is just a history? I need to send the message one time per session only.

Thank you in advance,
Serge

(Sergey) #2

Team, please give me any answer to the question. If it is impossible, I’ll show the answer to my boss and he won’t force me to do this feature.

Thank you in advance.

(Nathan Stults) #3

There is not any property on the message that can tell you if the message is just being sent or is being loaded from history. It isn’t clear why you would want to do this though - why not just have a normal flow respond to ‘Hi’ and say ‘Ask your question please’ instead trying to do it in the JavaScript API?

(Sergey) #4

Because I need to send some information about the current client to my chat flow. “Hi” and “Hi! Ask your question please” are just examples, really there will be more complex behaviour.

Anyway, thank you for the answer.

(Nathan Stults) #5

Note that anything you set on the metadata will be sent with each message silently, and you can update the metadata at any time, not just at startup. So if the browser learns something about the user it wants to send along with messages, it can set the metadata at that time and it will be send with the message the user sends.

(Sergey) #6

Thank you. But it is still impossible to send metadata without message, correct? So, we are still in the same problem - our API message appears twice (or more) if a user opens history.

Is there any way to send data from JavaScript to chat flow once per chat session ?

(Nathan Stults) #7

Not using the JavaScript API and a message - however you could set up a webhook flow and call it via Ajax that could potentially do the same thing, whatever that thing is