Skip to content

Instantly share code, notes, and snippets.

@lgaetz
Last active November 20, 2024 21:09
Show Gist options
  • Save lgaetz/ec3509da8d989a00064337f194b9d58e to your computer and use it in GitHub Desktop.
Save lgaetz/ec3509da8d989a00064337f194b9d58e to your computer and use it in GitHub Desktop.
Gentleman Caller
; FreePBX dialplan to schedule a call for future using Asterisk call file.
;
; License: GNU GPL3+
; latest version: https://gist.github.com/lgaetz/ec3509da8d989a00064337f194b9d58e
;
; Asterisk diaplan sub requires 3 arguments
; ARG1 = dialstring for first leg of call
; ARG2 = dialstring for second leg of call
; ARG3 = how many minutes in the future to schedule the call
;
; Usage example - to schedule a call 20 min in the future where extension
; 4003 rings and once answered gets bridged to the echo test feature code:
; GoSub(lgaetz-callfile,s,1(4003,*43,20));
;
; version history 2024-10-20 First commit working
[lgaetz-callfile]
exten => s,1,NoOp(Entering user defined context lgaetz-callfile in extensions_custom.conf)
; todo - add a check to confirm 3 args are set
exten => s,n,Set(call_filename=${ASTSPOOLDIR}/tmp/${UNIQUEID}.scheduled.call.${ARG3})
exten => s,n,System(rm -rf ${call_filename}) ; purge any existing call file with identical name - prob won't happen
exten => s,n,System(echo "Channel: Local/${ARG1}@originate-skipvm" >> ${call_filename})
exten => s,n,System(echo 'Callerid: <${ARG1}> "Scheduled Call"' >> ${call_filename})
exten => s,n,System(echo 'WaitTime: 30' >> ${call_filename})
exten => s,n,System(echo 'MaxRetries: 0' >> ${call_filename})
exten => s,n,System(echo 'Context: originate-skipvm' >> ${call_filename})
exten => s,n,System(echo 'Extension: ${ARG2}' >> ${call_filename})
exten => s,n,System(echo 'Priority: 1' >> ${call_filename})
exten => s,n,System(echo 'Archive: yes' >> ${call_filename})
; add as many variables as you need, they can be referenced directly as channel vars when
; the scheduled call occurs
exten => s,n,System(echo "Setvar: schedule_uniqueid=${UNIQUEID}" >> ${call_filename})
exten => s,n,System(echo "Setvar: call_delay=${ARG3}" >> ${call_filename})
exten => s,n,System(touch -d "+${ARG3} minutes" ${call_filename})
exten => s,n,System(mv ${call_filename} ${ASTSPOOLDIR}/outgoing)
exten => s,n,Return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment