Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot set channel variables after create #171

Open
gordongrech opened this issue Jan 15, 2024 · 1 comment
Open

Cannot set channel variables after create #171

gordongrech opened this issue Jan 15, 2024 · 1 comment

Comments

@gordongrech
Copy link

Hello,

I am originating a call to a channel. I need to set some SIP headers and to achieve this I am using channel create not originate, followed by the setting of the variables and dial. I am occasionally getting "Non-2XX response: 409 Conflict" errors when setting the variables.

The issue seems to go away if I wait for a bit after creating the channel (enters stasis?), however I would like to avoid blindly blocking execution. Could you kindly let me know if this is the correct approach or if there is there a better way to achieve this please?

func createChannel(client ari.Client, channel *ari.ChannelHandle, uri, callID, endpointID, callerNumber string) error {
	ch, err := client.Channel().Create(channel.Key(), ari.ChannelCreateRequest{
		Endpoint: uri,
		App:      "test",
	})
	if err != nil {
		return err
	}
	time.Sleep(time.Millisecond * 10)

	headers := map[string]string{
		"PJSIP_HEADER(add,X-Call-ID)":     callID,
		"PJSIP_HEADER(add,X-Endpoint-ID)": endpointID,
		"CONNECTEDLINE(num)":              callerNumber,
	}
	for key, value := range headers {
		if err = ch.SetVariable(key, value); err != nil {
			return err
		}
	}
	return channel.Dial(channel.ID(), 10)
}
@ronlockard
Copy link

I have had good luck using StageOriginate() and Exec() instead after running into a similar issue before. You can pass the channel variables in as part of the StageOriginate() call rather than set them individually after the create. It doesn't dial until you call Exec() on the channel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants