What's the correct way to set a pjsip header with lua?

I’ve tried setting a header with the following line. It’s not working:

channel.PJSIP_HEADER("add", "X-Dialed-Number"):set("8005550199")

Very few people use LUA, and the documentation on writing dialplan subroutines in LUA seems incomplete. However, are you running this code in the pre-dial subroutine?

Also note that only example I can find of setting a channel variable does not use :set.

1 Like

Thank you for the reply. Yeah I know, I made a mistake choosing pbx_lua for this project, but here we are…

This issue actually wasn’t a lua issue at all. Your answer, while unrelated, did get me thinking differently and I solved it.
https://wiki.asterisk.org/wiki/display/AST/Asterisk+19+Function_PJSIP_HEADER

According to the PJSIP_HEADER docs, setting the header will affect the incoming channel, not outgoing. You have to use a subroutine (gross).

Here’s what’s working for me. I hope someone in the future finds this helpful:

extensions = {

    ["test_context"] = {
        ["s"] = function (c, e)        
            app.dial("pjsip/8005550199@trunk,30,b(pjsip_handler^addheader^1(X-Dialed-Number^8775550122)")
        end,
    },

    ["pjsip_handler"] = {

        ["addheader"] = function (c, e)
            channel.PJSIP_HEADER("add", channel.ARG1:get()):set(channel.ARG2:get())  
            return app['return']()
        end,

    },
}

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.