简体   繁体   中英

Issue with CRMContainer in Twilio Flex

I built a simple plugin that shows in the CRMContainer the url of my CRM given some attributes parameters (if they are passed by), during inbound tasks this works fine, but the problem is that during outbound calls the behaviour is not the one expected, this is the piece of code:

flex.CRMContainer.defaultProps.uriCallback = (task) => {
  return task
 
    ? `https://mycrm.zzz/${task.attributes.clicar}/${task.attributes.contacth}/`
    : 'https://mycrm.zzz/contacts/';
  }

}

I would need an additional condition that tells the code, if this is an outbound voice call to always show a default url. I tried adding an if/else that checks if task.attributes.direction is outbound, but Flex says this is undefined. Any tip? Thanks

Max

The problem is that you aren't checking for the existence of the task . Your original code had this:

flex.CRMContainer.defaultProps.uriCallback = (task) => {
  return task
    ? `https://mycrm.zzz/${task.attributes.clicar}/${task.attributes.contacth}/`
    : 'https://mycrm.zzz/contacts/';
  }
}

Which returns the URL with the task attributes in it only if the task exists, because of the ternary conditional.

So, when you try to use the attributes you need to make sure the task exists. So taking your code from the last comment, it should look like this:

flex.CRMContainer.defaultProps.uriCallback = (task) => {
  if (task) {
    if (task.attributes.direction === 'outbound'){
      return `https://mycrm.zzz/${task.attributes.clicar}/${task.attributes.contacth}/`;
    } else {
      return `https://mycrm.zzz/contacts/`
    }
  } else {
    return 'https://mycrm.zzz/contacts/';
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM