簡體   English   中英

Twilio:來電等待轉接號碼(Dial)響應時的等待語音(Say)

[英]Twilio: Waiting voice (Say) while the caller is waiting for a response from forwarded number (Dial)

我為看似簡單的事情而苦苦掙扎:

當我接到 twilio 電話號碼的電話時,我想使用<Dial>轉接電話,並在來電者等待時播放一條消息,該消息也可以收集用戶輸入。

我設法轉發了一個電話,或者讓來電者在這里成為消息並收集輸入,但不是同時進行

這是我嘗試過的:

...
const response = new VoiceResponse()
response.dial('+33611182299')
response.enqueue({
    waitUrl: `https://myapi.com/api/repondeur/wait-msg`,
}, 'support')
...

我還嘗試在 waitUrl 中設置Dial ,以及許多不同的組合(例如更改順序、嘗試創建隊列等),但都沒有成功。

也試圖適應這個這個但它沒有用

你能指出我正確的方向嗎?

經過大量的試驗和 headbanging,這就是我得到的:


const inProgressCallsCache = {}


// MAIN WEBHOOK ROUTE
export const answerCallSvc = {
    route: '/answer-call',
    async main(body) {
        const response = new VoiceResponse()

        // First we redirect caller to the waiting url
        response.enqueue({
            waitUrl: url(`/answer-call/wait-msg`),
            method: 'POST',
        }, queueName)

        // Then we call the respondent. When he'll answer
        // the call will be redirected to `url`
        const call = await client.calls
            .create({
                to: telTest,
                from: body.Caller,
                url: url(`/answer-call/call-back`),
                method: 'POST',
                // time while trying to call respondent
                // before giving up
                timeout, 
            })

        // store the respondent SID in cache so we can
        // end the call if the user end the call
        // this is a HACK, it may need to be stored in DB
        inProgressCallsCache[body.CallSid] = call.sid

        return response.toString()
    },
}

export const answerCallCallback = {
    route: '/answer-call/call-back',
    async main() {
        // this allow the respondent to be connected to the caller 
        // once the respondent pick up the phone
        const response = new VoiceResponse()
        response.dial().queue(queueName)
        return response.toString()
    },
}

export const answerCallWaitMsgSvc = {
    route: '/answer-call/wait-msg',
    async main() {
        // wait url will be responsible for playing the message 
        // and gathering user input while the callers awaits
        const response = new VoiceResponse()
        const gather = response.gather({
            action: url(`/answer-call/record-input`),
            method: 'POST'
        })
        gather.say(`We are connecting you with someone. You can press any digit to end the call.`)
        return response.toString()
    },
}



export const answerCallRecordUserINput = {
    route: '/answer-call/record-input',
    async main(body) {
        // The user has pressed a digit so we may take further actions here
        // and end the call for both caller and respondent
        console.log(`Recorded input`, body.Digits)

        const callingSid = body.CallSid

        const response = new VoiceResponse()
        response.say(`Thank you, we will end the call now.`)
        response.hangup()

            const respondentSid = inProgressCallsCache[callingSid] 
            if (respondentSid) client.calls(respondentSid).update({ status: 'canceled' }).catch(err => console.error(err))

        return response.toString()
    },
}

如果您需要更多詳細信息或轉換為表達語法,請告訴我。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM