Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: Love Code
Added: Dec 19, 2018 2:53 AM
Modified: Dec 19, 2018 10:07 PM
Views: 42
Tags: no tags
  1. // Custom Actions that can be imported into plugin.js file
  2.  
  3. import axios from 'axios';
  4. import { Actions } from "@twilio/flex-ui";
  5.  
  6.  
  7. Actions.replaceAction("AcceptTask", (payload, original)=>{
  8. // console.log(payload.conferenceOptions);
  9. payload.conferenceOptions.endConferenceOnExit=true;
  10. return original(payload);
  11. });
  12.  
  13. Actions.addListener("beforeRejectTask", (payload, abortFunction) => {
  14.         // alert("Triggered after event RejectTask");
  15.     if (!window.confirm("Are you sure you want to reject the task and send to your non-flex agent")) {
  16.         abortFunction();
  17.     }
  18. });
  19.  
  20. Actions.replaceAction("RejectTask", (payload, original) => {
  21.  
  22.     return new Promise((resolve, reject) => {
  23.  
  24.       const task = payload.task;
  25.       const reservation = payload.task.sourceObject;
  26.       const callSid = task.attributes.call_sid;
  27.       const redirectUrl = 'https://persimmon-lizard-7500.twil.io/redirect';
  28.  
  29.       // you may want to check if there's any other available agent online before doing the redirect
  30.       // so wrap this in an if-else and do original(payload) if there's another available agent, which will kick to that agent
  31.       // this is assuming that all agents are equal in skills
  32.  
  33.       reservation.redirect(callSid, redirectUrl, {accept: false} )
  34.      
  35.  
  36.       axios({
  37.         method:'post',
  38.         params: {
  39.           taskSid: task.taskSid
  40.         },
  41.           url:'https://persimmon-lizard-7500.twil.io/deleteTask', //use a twilio function to update the Task status
  42.       })
  43.  
  44.       resolve();
  45.  
  46.       })    
  47.   });
  48.