CyCoreSystems / ari

Golang Asterisk REST Interface (ARI) library
Apache License 2.0
180 stars 74 forks source link

Having troubles to orignate #173

Open disolaterX opened 3 months ago

disolaterX commented 3 months ago
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 anonymous@anonymous.invalid
  Timeout:   30,
})

here endpoint value is

 PJSIP/superfone_number/sip:su_15@10.140.0.10: Non-2XX response: 400 Bad Request

the same work in dial() in extension but how to achive same where I want to call this su_15@10.140.0.10 it exist on kamilio

(edited for formatting/readability)

Ulexus commented 3 months ago

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 commented 3 months ago

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 commented 3 months ago

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