Freshchat Event.helper.done() not working properly

Hi,

I am intercepting a onSendclick event to be able to pass a translation to text that is going to be send. However for some reason the event.helper.done() is not properly working. I am basing my code on this documentation:

Inside my callback function I make two apicalls to the google translate api so I can translate the text from the message. After that I will send the new message as an agent message to the Freshchat api. So in short three apicalls. This flow works and will work when a boolean(isEnabled) is set to true (means the app is supposed to be active). However when the boolean is set to false and the onSendClick callback function should continue the event by using even.helper.done() the original message is not put through. I cannot figure out why not as it seems the even.helper.done() simply does not continue the event.
taken from the documentation:

// To allow the original event to continue
event.helper.done()

// To prevent the original event from completing
event.helper.fail(‘errorMessage’)

Below is the callback function in question:

    function pickUpSendClick(event) {

       if(!isEnabled){

        event.helper.done()

      } else if(isEnabled){

        event.helper.fail("Stop the event");

      const data = event.helper.getData();

      var translateText = data.conversation.messages[0].message_parts[0].text.content;

      var conversationId = data.conversation.id;

      var messageType = data.conversation.messages[0].message_type;

      var translationObj = {

        sourceLang: agentLangCode,

        targetLang: arrUserObj.userLangCode,

        textToTranslate: translateText

      };


      var detectionObj = {

        textToTranslate: translateText

      };



      makeApiRequest(endpoints.detect, detectionObj, "GET", false).then(function (resp) {

        source = resp.data.detections[0][0].language;



        if (source != agentLangCode) {

          translationObj.sourceLang = source

        }


        //1. source ophalen uit agent api call

        // 2. target language ophalen uit user api call

        //3. translate text

        //4. sned new message in name of user id


        //MessageType normal: private messge should not be included here

        //Agentlangcode cannot be the same as userlangcode because google does not translate from and too the same language

        //Source cannot be the same as userLangcode because google does not translate from and to the same language

        if ((messageType === "Normal") && (agentLangCode != arrUserObj.userLangCode) && (source != arrUserObj.userLangCode)) {


          makeApiRequest(endpoints.detect, detectionObj, "GET", false).then(function (resp) {

            source = resp.data.detections[0][0].language;

            conf = resp.data.detections[0][0].confidence.toFixed(2) * 100;


            if (source != agentLangCode) {

              translationObj.sourceLang = source

            }



            // translate(translationObj);

            makeApiRequest(endpoints.translate, translationObj, "GET", false).then(function (data) {

              console.log("This is the translatedText: " + data);

              var parsedTranslations = data.data.translations[0].translatedText;

              var parsenText = JSON.stringify(parsedTranslations);

              console.log("This language is about to be translated: " + parsenText);


              var url = "https://loyally1.freshchat.com/v2/conversations/" + conversationId + "/messages";



              var messageObject = {

                "actor_type": "agent",

                "actor_id": agentId,

                "message_type": "normal",

                "message_parts": [

                  {

                    "text": {

                      "content": parsenText

                    }

                  }

                ]

              }


              var headers = getFreshchatHeaders();

              var body = JSON.stringify(messageObject);

              var type = "POST";


              callApiRequest(type, headers, url, body).then(function (data) {

                console.log("Are you here two: " + JSON.stringify(data));

                console.log("Succesfully posted the message.");

                if (data.status == 200) {

                  console.log("response status succesful");


                  JSON.parse(data.response);


                }

              })

            })

          })


      

    } else {

      event.helper.done()

    }

`  })`

    }else if(!isEnabled){

      event.helper.done()

    }

    }

If you need more information please let me know.

With kind regards,
Martijn van der Linden

@LylMartijn - As far as I understand when the app is not enabled, the message that needs to be sent shouldn’t need to be translated, and an original message sent by the user should be sent untranslated.

This brings me to learn that event.helper.done() doesn’t allow the untranslated messages to be sent to the user.

In that case, what happens? Do messages not get sent at all?

Hi Saif, Sorry for the late response. I was on holiday. But yes you are correct, this what is suppose to happen. When the app is not enabled Freshchat should just send the original message. According to documentation you sholud be able to continue the original event with event.helper.done().

However this does not work.