Ok new problem.
If I have multiple entries for mapping extensions to DID’s it doesn’t work.
That is for either direction.
[dummy-answer]
exten => s,1,Answer()
same => n,Wait(5)
same => n,Hangup()
[skyetel-sms]
exten => s,1,Answer()
same => n,Set(SMS_FROM=${FILTER(0-9,${from})})
same => n,Set(SMS_TO=${FILTER(0-9,${to})})
same => n,Set(MESSAGE(body)=${body})
same => n,Noop(From: ${SMS_FROM})
same => n,Noop(TO: ${SMS_TO})
same => n,Noop(Body: ${MESSAGE(body)})
same => n,Set(SMS_TO=${IF($[“${SMS_TO}”=“1XXXXXXXXXX”]?116:116)})
same => n,Set(TENANT=tenant)
same => n,Set(DIAL_STRING=${DB(${TENANT}/extensions/${SMS_TO}/dial)})
same => n,GotoIf($[“${DIAL_STRING}”=“”]?sendfailedmsg)
same => n,Set(COUNTER=1)
same => n,Set(CURRENT_DEVICE=${CUT(DIAL_STRING,&,${COUNTER})})
same => n,While($[${EXISTS(${CURRENT_DEVICE})}])
same => n,Set(TECHNOLOGY=${CUT(CURRENT_DEVICE,/,1)})
same => n,Set(USER=${CUT(CURRENT_DEVICE,/,2)})
same => n,GotoIf($[$[“${TECHNOLOGY}”=“IAX2”]|$[“${TECHNOLOGY}”=“DAHDI”]]?next)
same => n,MessageSend(${TOLOWER(${TECHNOLOGY})}:${USER},${SMS_FROM})
same => n,NoOp(SMS Status to ${CURRENT_DEVICE}: ${MESSAGE_SEND_STATUS})
same => n(next),Set(COUNTER=$[${COUNTER} + 1])
same => n,Set(CURRENT_DEVICE=${CUT(DIAL_STRING,&,${COUNTER})})
same => n,EndWhile()
same => n,Goto(h,1)
same => n(sendfailedmsg),Noop(The message to extension ${SMS_TO} has failed. Status: ${MESSAGE_SEND_STATUS})
same => n(failed),Hangup()
[messages]
exten => ZXXXXXX!,1,Noop(SMS Sending) ;Accepts 7 or more digits with the first digit being [1-9]
same => n,GotoIf($[“x${CUT(MESSAGE(to),<,2)}x”=“xx”]?noname)
same => n,Set(SMS_NUM=${CUT(MESSAGE(to),<,2)})
same => n,Set(SMS_NUM=${CUT(SMS_NUM,>,1)})
same => n,Set(SMS_TECH=${CUT(SMS_NUM,:,1)})
same => n,Set(SMS_REAL_TECH=${CUT(MESSAGE(to),:,1)})
same => n,GotoIf($[“${SMS_TECH}”=“${SMS_REAL_TECH}”]?noname)
same => n,Set(MESSAGE(to)=${STRREPLACE(SMS_NUM,${SMS_TECH},${SMS_REAL_TECH})})
same => n(noname),Set(SMS_TO=${FILTER(0-9,${CUT(MESSAGE(to),@,1)})})
same => n,GotoIf($[${LEN(${SMS_TO})} < 10]?messages-internal,${EXTEN},1)
same => n,ExecIf($[“${LEN(${SMS_TO})}”=“10”]?Set(SMS_TO=1${SMS_TO}))
same => n,ExecIf($[${LEN(${SMS_TO})} > 11]?Hangup())
same => n,Set(FROM=${CUT(MESSAGE(from),<,2)})
same => n,Set(ACTUALFROM=${CUT(FROM,@,1)})
same => n,ExecIf($[“${ACTUALFROM}”=~"“]?Set(ACTUALFROM=${CUT(ACTUALFROM,_,1)}))
same => n,Set(SMS_FROM=${FILTER(0-9,${CUT(ACTUALFROM,:,2)})})
same => n,Set(SMS_CID=${IF($[”${SMS_FROM}"=“116”]?1XXXXXXXXXX)
same => n,Noop(To: ${SMS_TO})
same => n,Noop(From: ${SMS_FROM})
same => n,Answer()
same => n,Set(SendSMS=${SHELL(curl -X POST -v -H “Content-type: application/json” --user user:pass --data “{ "to": "${SMS_TO}", "text": "${MESSAGE(body)}" }” https://sms.skyetel.com/v1/out?from=${SMS_CID})})
same => n,Hangup()