Ready to go plain Asterisk sip message queueing script

I have written a ready to go plain Asterisk script solution for queueing SIP messages that can’t be delivered at the time of sending. The message will be stored and when the routine is run and the sip phone is ready to receive, delivered. The script is written for 4 digits phone numbers. With shorter or longer numbers a small adjustment has to be made at line 179. SET(NAME_LENGTH=22) is based on a 4 digit phone number. Explanation and instruction is added to the pastetbin dump. I hope it is useful to somebody.