0

I'm implementing warm-transfer in my App suggested by Twilio.
I need all this feature as follows:
https://www.twilio.com/docs/voice/tutorials/warm-transfer

I downloaded this sample from Github to check if this approach will be suitable:
https://github.com/TwilioDevEd/warm-transfer-csharp

Now the problem I'm facing is, I cannot put the first caller on hold listening to some music while 1st agent calls to 2nd agent and tell them about caller's problem and hang up themselves(i.e. 1st agent)

I have added this piece of code in the sample code to put caller on hold:

public async Task<ActionResult> CallAgent2(string agentId)
    {
        var call = await _callsRepository.FindByAgentIdAsync(agentId);
        var participant = ParticipantResource.Update(
            pathConferenceSid: call.ConferenceId,
            pathCallSid: call.ConferenceId,
            hold: true,
            holdUrl: new System.Uri("http://twimlets.com/holdmusic?Bucket=com.twilio.music.classical")
        );

        var callBackUrl = GetConnectConfereceUrlForAgent(agentId, call.ConferenceId);
        _callCreator.CallAgent("agent2", callBackUrl);
        return new EmptyResult();
    }

But I'm getting error of "Error 20404" by Twilio.
Please let me know how can I achieve this or if I can use some other better approach to fulfill my requirement.

Raj Gupta
  • 65
  • 8
  • A 20404 is a missing resource (essentially a 404). Looks like you might be using the conference ID twice when you need the call sid for the `pathCallSid` parameter instead. – philnash Mar 14 '19 at 02:32
  • Yes, that's how it's done in the sample code. Actually when a first calls comes in, its callSid becomes as conferenceSid. I tried to give a random name to the conferenceSid and access ParticipantResource.Fetch function using that random name but still the same problem. – Raj Gupta Mar 14 '19 at 02:41

1 Answers1

0

Twilio developer evangelist here.

You are getting a 20404 error because you are trying to reference a resource that doesn't exist by passing a conference SID as the parameter that needs a call SID.

Conferences and calls are different resources, which is why to refer to a participant in a conference you need the conference SID and the participant's call SID.

You have the Call SID, which is confusingly referred to as the conference ID, but that is because it used as the friendly name when creating the TwiML to dial someone into a conference.

Since it is the friendly name, this means we can look up the conference by filtering by the friendly name.

var conferences = ConferenceResource.Read(
    friendlyName: conferenceId,
    status: ConferenceResource.StatusEnum.InProgress
);

This returns all the in progress conferences with the friendly name the same as the call SID. This will be at most one conference. You can then use the conference SID, along with the call SID to update the participant. Try something like this:

public async Task<ActionResult> CallAgent2(string agentId)
{
    var call = await _callsRepository.FindByAgentIdAsync(agentId);
    var conferences = ConferenceResource.Read(
        friendlyName: conferenceId,
        status: ConferenceResource.StatusEnum.InProgress
    );
    var conference = conferences[0];
    var participant = ParticipantResource.Update(
        pathConferenceSid: conference.Sid,
        pathCallSid: call.ConferenceId,
        hold: true,
        holdUrl: new System.Uri("http://twimlets.com/holdmusic?Bucket=com.twilio.music.classical")
    );

    var callBackUrl = GetConnectConfereceUrlForAgent(agentId, call.ConferenceId);
    _callCreator.CallAgent("agent2", callBackUrl);
    return new EmptyResult();
}
philnash
  • 70,667
  • 10
  • 60
  • 88
  • That ID given in the model is a primary key in the table as integer that will not work. I'm not sure how to get pathConferenceSid. I guess pathConferenceSid is generated from Twilio because when an agent is joining a new conference using: **new Dial().Conference( "xyz", waitUrl: new System.Uri(waitUrl));** and when I'm accessing using: **ParticipantResource.Fetch("xyz", call.SiD)** is giving me same 20404 error. Here **xyz** is a random name given by me. – Raj Gupta Mar 14 '19 at 04:54
  • Oh, you're right. We don't ever get the conference SID, just the call SID. I've updated my answer with a different idea. – philnash Mar 14 '19 at 05:30
  • Perfect! This is what I was looking for. It's working now. – Raj Gupta Mar 14 '19 at 08:51
  • Fantastic! Glad I could help out. – philnash Mar 14 '19 at 08:52