Git Product home page Git Product logo

Comments (1)

jorgeluiso avatar jorgeluiso commented on August 22, 2024

Let's think of the CSAT survey as a business initiated flow. All business initiated flows need to respect the 24hr policy, we therefore should track the last user message that we got.

Possible Solution

Define a required inactivity period to be eligible for a survey (quiet time 60s). The implementation will sleep for a minute, and check if the user has not messaged the app in the last minute. If that is not the case wait for a final second time.

  static genAgentRating(agent) {
    // This is only triggered 1 min after talking with an agent as long as nothing else happened in between
    delay = "60000";
    setTimeout(() => sendCSATRequest(user, agent, delay), delay);
    return;
  }
  • Add to on survey.js the sendCSATMessage function:
function sendCSATMessage(user, agent, delay){
  // It's a good practice to always validate this even if is not possible given the proposed params.
  if(!user.withinPolicyMessagingWindow())
    return;
  // Once HOP Support is done, check that this app owns the thread.
  if(user.primaryReceiver() !== config.app_id)
    return;
  if(Date.now() - delay < user.last_user_activity){
    return;
  }
  let response = Response.genQuickReply(
      i18n.__("survey.prompt", {
        agentFirstName: agent
      }),
      [
        {
          title: "\uD83D\uDE00",
          payload: "CSAT_GOOD"
        },
        {
          title: "\uD83D\uDE42",
          payload: "CSAT_AVERAGE"
        },
        {
          title: "\uD83D\uDE41",
          payload: "CSAT_BAD"
        }
      ]
    );
  // send the message 
  let requestBody = {
      recipient: {
        id: user.psid
      },
      message: response
    };
  GraphAPi.callSendAPI(requestBody);
}

from original-coast-clothing.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.