How to answer a call via Sip trunk

Hi I have an AGI script that is running on my Asterisk server.I’m using an OpenVox GSM gateway.I want to answer to a call using a specific trunk and a specific number.
This is the syntax I use to execute my AGI script in local way :
[test40]
exten => 2040,1,Answer(500)
same => 2, Set(CHANNEL(language)=moore)
same => 3,Agi(test.php,1612279908)
same => 4,Hangup()

When calling 2040 I can execute my AGI Script.
Now I want to call a number inserted in my gateway via Sip trunk
I tried like this : exten => 2040,1,Answer(SIP/1002/500) 1002 is the trunk but It doesn’t work.
Is someone can help me with the correct answer?
Thanks

This doesn’t make sense to me. You can only answer the call on the current channel, and the source endpoint/peer for that is already fixed at the point the channel is created. Also, even a cursory examination of the documentation for Answer will tell you that the first parameter is an integer number and there is only one possible value for any second parameter.

What are you really trying to achieve, as against how are your trying to achieve it?

Ahhh I see.
I juste want to call the number inserted on the openvox gsm gateway and the calling of this number will execute the AGIscript.

That just sounds like an incoming SIP call. You handle it exactly the same as a call from a local SIP phone, in the same context, except that the initial value of ${EXTEN} might be fixed by the gateway, or the gateway may not provide a user part at all, in which case Asterisk will treat it as though the user part was s.

Have you an example for me please?
For me I think It’s SIP/theTrunknumber/local exentension

That’s a dial string for an outgoing call, but you seem to be asking about handling an incoming call.

Except for the direction of registration, this is no different from how you handle an internet telephony service provider. In any case, as a general principle, I avoid giving examples; people tend to copy them without understanding them. And, in this case the only bits of the requirement that are difficult are those for which I don’t know the fine details, e.g. the way the gateway forms the request URI, so I’d have to make guesses, which might well be wrong.

Either you are overcomplicating this, or you haven’t properly explained what you are trying to do. As you haven’t provided a high level description of the requirement, I can’t rule out the latter.

Ok I explain you the scenario.
74XXXXXX is an international number inserted in a GSM Gateway.The gateway is connected to a freepbx/asterisk server.
I can execute an AGI script when calling the local number 2040. i can also execute the AGI script when I call the international number only If I create a custom destination on Freepbx.
Now I want a syntax that I’ll use to make an inconming call on my 74XXXXXX number.
I’ll put this syntax on asterisk/extensions_custom.conf file.
Something like this
#[test40]
exten => s,1,Answer()
exten => s,2,Dial(SIP/2040)
exten => s,3, Agi(test.php,1612279908)
exten => s,4,Hangup()

Here exten => s,2,Dial(SIP/2040) is to call the local extension
How can I call the international number?

It’s what I want to achieve

Incoming calls can only be made by the other party making an outgoing call. If you want an incoming call to arrive over a GSM network, the corresponding outgoing call has to be made over the PSTN. If you want to make the outgoing call from the same PABX, you will need to buy services from someone who provides PSTN access, which might be over an analogue line, an ISDN connection, VoIP, or a mobile network gateway.

This is my best guess as to your meaning, but I’m still confused.

Also, this forum doesn’t support FreePBX, so “custom destination” doesn’t mean anything.