text: import { createCallActivity } from '@apps/phone/services/calls'
  import Call from '@apps/phone/models/call'
  import twilio from '@core/vendor/twilio'
  import Twilio from 'twilio'
  import btoa from 'btoa'
  
  const unholdRoute = async (req, res) => {
  
    const call = await Call.query(qb => {
      qb.where('id', req.params.id)
    }).fetch({
      transacting: req.trx
    })
  
    if(!call) return res.status(404).json({
      code: 404,
      message: 'Unable to load call'
    })
  
    const twiml = new Twilio.twiml.VoiceResponse()
  
    const dial = twiml.dial()
  
    const client = dial.client({
      statusCallback: `${process.env.WEBHOOK_HOST}/voice/status?call_id=${call.get('id')}`,
      statusCallbackEvent: ['initiated','ringing','answered','completed']
    })
  
    client.identity(req.user.get('id'))
  
    client.parameter({
      name: 'config',
      value: btoa(JSON.stringify({
        action: 'unhold',
        call: {
          id: call.get('id')
        }
      }))
    })
  
    await createCallActivity(req, {
      id: call.get('id'),
      type: 'unhold'
    })
  
    await twilio.calls(req.body.sid).update({
      twiml: twiml.toString()
    })
  
    await res.status(200).respond(true)
  
  }
  
  export default unholdRoute
  