-3

A call (A) arrives on Asterisk. It is picked up by our dialplan and routed to the php file whose mission is to manage the call. The call is put on hold with the MusicOnHold function. So far it's ok.

The objective is during this wait, to make an outgoing call (B) to the customer and ask them if they wish to take the call or not (via DTMF).

If we do the Dial function directly, as soon as the outgoing call (B) is picked up by the customer, then call A and B are connected. What we don't want.

How do I initiate a call on a new channel without call A being connected immediately? Do we have to go through the AMI?

We used the AGI php and the dialplan with Gosub.

Since PHP is synchronous, you cannot make a call B while call A is on hold.

David Makogon
  • 69,407
  • 21
  • 141
  • 189
BenC
  • 3
  • 2
  • 1
    Are you just looking for general suggestions or wanting someone to write code for you? Neither are really a good fit for Stack Overflow. If you're having problems with a specific piece of code, you should include a [mre] here. – miken32 May 16 '23 at 19:09

2 Answers2

0

You are doing it wrong way.

What should you do

  1. Dial command with m param(play music)
  2. Dial command(same) with U param(sub-macro before connect).

Play music in first, create dialplan for ask client at second.

You can also google "asterisk privacy macro" for how that should looks like.

There are NO NEED in any AGI or external routine here.\

If you are still insist you have do it wrong way - you have app_bridge and app_conference for that. There is also possible to do something via async AGI/Stasis app. But that is also wrong way.

arheops
  • 15,544
  • 1
  • 21
  • 27
  • Thank you for your reply! I don't understand when you say to do in 1) a Dial with the m function and another Dial with the U function. Are you talking about different DIALs? Here is the Dialplan I'm running: – BenC May 17 '23 at 17:33
  • If you don't know what is application dial, you should start first from some asterisk basic. There is no way you will create valuable app without know basic, sorry. https://wiki.asterisk.org/wiki/display/AST/Asterisk+16+Application_Dial – arheops May 17 '23 at 23:48
  • No, it is different argument for one dialout. – arheops May 17 '23 at 23:48
  • I have already tested the Dial with the 2 arguments but I can't get the result. here is the code of the Dial same =n, Dial(SIP/0754231245@TRUNKAI2,30,m(default),U(subDialer)); At this moment the sounds are played but when the called party picks up they are immediately connected without the SubDialer being played. Conversely if encodes the Dial, ial(SIP/0754231245@TRUNKAI2,30,U(subDialer)); the Sub is well played but not the music. that's where I'm stuck. Thank you for your help. – BenC May 18 '23 at 06:38
  • Read carefully doc. subDialler is dialplan section, not music. Also check about how asterisk arguments passed to dial command, plenty examples on web. – arheops May 18 '23 at 13:35
0

You need the knowledge of AMI and AGI to do this. In my case I use PHP (PAGI and PAMI).

file 1: agi-callin.php
file 2: agi-callout.php

Purpose: to have information from the 2 channels to perform a bridge action.

When call 1 arrives, it goes into agi-callin.php. To put it on hold, play the music

$agi->set_music(class_music)

. After playing the music, we call PAMI in file 1 to connect to the AMI and launch an action. It's the originate action that needs to be launched on the number you want to connect to call 1 and listen to the originate events of this action using the actionID.

$originate = new OriginateAction("SIP/101");
$originate->setContext('default');
$originate->setExtension("agi-callout");
$originate->setPriority(1);
$originate->setAsync(true);
$response = $pami->send($originate);

//Event listener for all event AMI
$pami->registerEventListener(function (EventMessage $event) {
       var_dump($event);
});

After listening to the originate event that launched call 2, we can obtain the channel for call 2 using the actionID returned by the response to the previous originate action. Once the 2 channels have been retrieved, simply launch an action bridge from PAMI to link the 2 calls.

bridge = new BridgeAction($channel1, $channel2);
$response = $pami->send($bridge);

Elierak26
  • 38
  • 1
  • 1
  • 6