How to read headers of a BYE message with PJSIP_HEADER?

Hello everyone.
I had a problem switching from Asterisk version 13 to version 20.
Previously I could get information from the BYE headers with SIP_HEADER, with which I transferred the call. When changing to version 20 and using PJSIP_HEADER I do not get the same result.
Attached is the dialplan with SIP:

[contex]
exten => _1XXXX,1,NoOp()
same => n,Set(CALLERID(all)=Asterisk <${UNIQUEID}>)
same => n,Set(_MCHAN=${CHANNEL})
same => n,Dial(SIP/test/sip:XXX@aaaa.com,gb(contex^callee_handler^1))
same => n,NoOp(Transfer to ${SHARED(TRANSFERTO)})
same => n,Transfer(SIP/${SHARED(TRANSFERTO)})
same => n,Hangup()

exten => callee_handler,1,NoOp()
same => n,Set(CHANNEL(hangup_handler_push)=contex,hangup_handler,1);
same => n,Return()
exten => hangup_handler,1,NoOp()
same => n,Set(SHARED(TRANSFERTO,${MCHAN})=${SIP_HEADER(read,X-message)})
same => n,Return()

Dialplan PJSIP:

[contex]
exten => _1XXXX,1,NoOp()
same => n,Set(CALLERID(all)=Asterisk <${UNIQUEID}>)
same => n,Set(_MCHAN=${CHANNEL})
same => n,Dial(PJSIP/test/sip:XXX@aaaa.com,gb(contex^callee_handler^1))
same => n,NoOp(Transfer to ${SHARED(TRANSFERTO)})
same => n,Transfer(PJSIP/${SHARED(TRANSFERTO)})
same => n,Hangup()

exten => callee_handler,1,NoOp()
same => n,Set(CHANNEL(hangup_handler_push)=contex,hangup_handler,1);
same => n,Return()
exten => hangup_handler,1,NoOp()
same => n,Set(SHARED(TRANSFERTO,${MCHAN})=${PJSIP_HEADER(read,X-message)})
same => n,Return()

Is there a way to get the BYE message with PJSIP?
I hope someone can help me.

Unless you’ve patched Asterisk, that hasn’t been supported in either chan_sip or chan_pjsip ever. It’s only worked on headers in INVITE.

It was decided to continue working with version 13 and chan_sip. If anyone wants to recreate it I attach the result.