"No target channel found" on pickup

I have extension 100 (snom 320) and 101 (snom 320) and queue 200. Extension 100 is watched by extension 101 and part of queue 200. If extension 100 is called directly extension 101 can pickup the call via a blinking button on the snom. If extension 100 is called via queue 200 and the blinking button on 101 is pressed 101 sees “declined” in the display and the messages log says

chan_sip.c: Trying to pick up 100@from-internal
app_directed_pickup.c: No target channel found for 100@from-internal.

Important parts of sip.conf:

[general]
sendrpid=pai
context = from-sip-external
notifyringing=yes
notifyhold=yes
notifycid=yes
limitonpeers=yes
call-limit=99
callcounter=yes
counteronpeer=yes
allowsubscribe=yes


[100]
username=100
type=friend
qualify=no
port=5060
pickupgroup=1
nat=no
mailbox=100@default
host=<phone-ip>
fromdomain=my.domain.com
dtmfmode=rfc2833
dial=SIP/100
context=from-internal
canreinvite=no
callgroup=1
callerid=phone 100 <100>
call-limit=6

[101]
username=101
type=friend
qualify=no
port=5060
pickupgroup=1
nat=no
mailbox=101@default
host=<phone-ip>
fromdomain=my.domain.com
dtmfmode=rfc2833
dial=SIP/101
context=from-internal
canreinvite=no
callgroup=1
callerid=phone 101 <101>
call-limit=6

Important parts of extensions.conf:

[from-internal]
include => ext-local

[ext-local]
exten => 100,hint,SIP/100
exten => 101,hint,SIP/101

[ext-queues]
exten => 321,1,Answer
exten => 321,n,Queue(321,t,,,60)

I’m using Asterisk 11.7. I was already playing with notifycid=ignore-context and PICKUPMARK but didn’t get it working. Any idea?

What is the part of the dialplan where you do the pickup?

Did you try using PickupChan?

I was not using the dial plan to do pickup here. I used the replaces header in the invite as described here as method 1: wiki.snom.com/Category:HowTo:Call_Pickup

As I said, this is working if the extension is called directly but not if called by the queue application.

I did the following changes to chan_sip.c of Asterisk 1.8.0

*** 14624,14647 ****
  				/* We create a fake call-id which the phone will send back in an INVITE
  				   Replaces header which we can grab and do some magic with. */
  				if (sip_cfg.pedanticsipchecking) {
! 					ast_str_append(tmp, 0, "<dialog id=\"%s\" call-id=\"pickup-%s\" local-tag=\"%s\" remote-tag=\"%s\" direction=\"recipient\">\n",
! 						exten, p->callid, p->theirtag, p->tag);
  				} else {
! 					ast_str_append(tmp, 0, "<dialog id=\"%s\" call-id=\"pickup-%s\" direction=\"recipient\">\n",
! 						exten, p->callid);
  				}
  				ast_str_append(tmp, 0,
  						"<remote>\n"
  						/* See the limitations of this above.  Luckily the phone seems to still be
  						   happy when these values are not correct. */
  						"<identity display=\"%s\">%s</identity>\n"
! 						"<target uri=\"%s\"/>\n"
  						"</remote>\n"
  						"<local>\n"
  						"<identity display=\"%s\">%s</identity>\n"
  						"<target uri=\"%s\"/>\n"
  						"</local>\n",
! 						remote_display, remote_target, remote_target, local_display, local_target, local_target);
  			} else {
  				ast_str_append(tmp, 0, "<dialog id=\"%s\" direction=\"recipient\">\n", exten);
  			}
--- 14624,14647 ----
  				/* We create a fake call-id which the phone will send back in an INVITE
  				   Replaces header which we can grab and do some magic with. */
  				if (sip_cfg.pedanticsipchecking) {
! 					ast_str_append(tmp, 0, "<dialog id=\"%s\" direction=\"recipient\">\n",
! 						exten);
  				} else {
! 					ast_str_append(tmp, 0, "<dialog id=\"%s\" direction=\"recipient\">\n",
! 						exten);
  				}
  				ast_str_append(tmp, 0,
  						"<remote>\n"
  						/* See the limitations of this above.  Luckily the phone seems to still be
  						   happy when these values are not correct. */
  						"<identity display=\"%s\">%s</identity>\n"
! 						"<target uri=\"sip:**%s@%s\"/>\n"
  						"</remote>\n"
  						"<local>\n"
  						"<identity display=\"%s\">%s</identity>\n"
  						"<target uri=\"%s\"/>\n"
  						"</local>\n",
! 						remote_display, remote_target, exten, p->fromdomain, local_display, local_target, local_target);
  			} else {
  				ast_str_append(tmp, 0, "<dialog id=\"%s\" direction=\"recipient\">\n", exten);
  			}

This causes the phone to switch to method 2 not using the replaces header but making an invite to the remote target URI (see link above). And here I think the following part of my dialplan is used:

Now the pickup of calls from queues is working. I wonder if my changes have bad side effects or if there is an easier way without having to change the code of Asterisk?