ari icon indicating copy to clipboard operation
ari copied to clipboard

Having troubles to orignate

Open disolaterX opened this issue 1 year ago • 3 comments

newChannelKey := ari.NewKey(ari.ChannelKey, url.QueryEscape(fmt.Sprintf("channel:%s", endpoint+time.Now().String())))
log.Printf("Originate call to %s\n", newChannelKey)
channel, err := client.Channel().Originate(newChannelKey, ari.OriginateRequest{
  Endpoint:  endpoint,
  Extension: "s",
  Context:   "inbound",
  Priority:  1,
  CallerID:  endpoint, // Optional: Set CallerID if you want to override [email protected]
  Timeout:   30,
})

here endpoint value is

 PJSIP/superfone_number/sip:[email protected]: Non-2XX response: 400 Bad Request

the same work in dial() in extension but how to achive same where I want to call this [email protected] it exist on kamilio

(edited for formatting/readability)

disolaterX avatar Mar 29 '24 14:03 disolaterX

That channel ID is a real mess, and while you are escaping it for URL usage, I suspect it is still going to have invalid characters from Asterisk's point of view. There's a reason we have the rid package in this library: to construct resource IDs.

newChannelKey := ari.NewKey(ari.ChannelKey, rid.New(rid.Channel))

Then, if you really need to know the timestamp of that, you can get it back with:

ts, err := rid.Timestamp(newChannelKey.ID)

But that will give you a nice, completely valid channel ID with no special characters.

Ulexus avatar Apr 07 '24 19:04 Ulexus

Oh, I think you're trying to pass the new, non-existent channel key into Originate as the first argument. The first argument to Originate is a related channel, from which ari can determine which Asterisk node to schedule it and from which Asterisk can determine how to most advantageously configure the new channel to work with it (such as avoiding transcoding).

See the comment on the Originate function: https://pkg.go.dev/github.com/CyCoreSystems/ari#Channel

Ulexus avatar Apr 07 '24 20:04 Ulexus

If you don't have a related channel, just pass nil as the first argument.

Ulexus avatar Apr 07 '24 20:04 Ulexus