Search code examples
voipasterisk

PBX Call makes another call and spy


When a user makes a call to my pbx, he needs to enter another phonenumber. Then asterisk should call that number and when the owner of that number takes the phone, asterisk should play a sound.

The user who made the call to my pbx, can listen live to the other call, he will hear the sound played from the pbx and the sound of the user.

What is the best way to do this?


Solution

  • Here is my solution

    *I wrote it in AEL, much easier to understand

    First I assume you got the callee number and file you want to play:

    context Start 
    {
      catch s {
                Wait(1);
                ...
                __NumberToDial=<Number that caller picked>;
                FileName=<File you want to play>;
                ...
                // I used SHARED variables to pass all the necessary data to sub channel
                SHARED(FileName)=${FileName};
                __Channel="${CHANNEL(name)}";
                Dial(Local/${CALLERID(num)}@Originate/n,,g);
      }
    }
    
    context Originate {
            _X. => { 
                Originate(SIP/<YourDialOutTrunk>/${NumberToDial},exten,Play,${Channel},1);
                if (${ORIGINATE_STATUS}!=SUCCESS)
                {
                   //do stuff if not connected...
                }
                else
                        ChanSpy(,qsSg(${Channel}));
             }
    }
    
    context Play {
            _X. => {
                    Channel="${CUT(EXTEN,?,1)}";
                    Set(SPYGROUP=${Channel});
                    FileName=${SHARED(FileName,${Channel})};
                    Playback(${FileName});
             }
    }
    

    *add w option to ChanSpy if you want to allow whisper/talk
    I didn't test this whisper!
    You need to add catch => h everywhere and rest of the logic you need.
    Whit this you will get the good timing. Only problem is to kill Originate channel if caller decide to hangup, which I've done sending channel kill on AMI with AGI script sending it channel name... bla bla... :)

    Hope it helps :)