variable length number

This commit is contained in:
JerryXiao 2021-11-23 13:36:15 +08:00
parent 7f331ce840
commit f0f29b3b0a
Signed by: Jerry
GPG key ID: 22618F758B5BE2E5
3 changed files with 57 additions and 49 deletions

View file

@ -4,26 +4,29 @@ writeprotect=no
clearglobalvars=no clearglobalvars=no
[extdn42whois] [extdn42whois]
exten => _X.,5,Set(CALLNUM=${EXTEN}) exten => _X!,200,Set(CALLNUM=${EXTEN})
same => n,Goto(s,1) same => n,Goto(s,1)
exten => s,1,Playback(silence/1) exten => s,1,Playback(silence/1)
same => n,Set(USERINPUT=) same => n,Set(USERINPUT=)
same => n,Read(USERINPUT,jerry-whois,10,,1,6) same => n,Read(USERINPUT,jerry-whois,10,,1,6)
same => n,GotoIf($["${READSTATUS}" = "TIMEOUT"]?s,1:) same => n,GotoIf($["${READSTATUS}" = "TIMEOUT" & "${USERINPUT}" = ""]?s,1:)
same => n,GotoIf($["${USERINPUT}" = ""]?extmymenu,${CALLNUM},5:whois,1) same => n,GotoIf($["${USERINPUT}" = ""]?extmymenu,${CALLNUM},200:whois,1)
exten => whois,1,Set(SESSIONUNID=${RAND(0,100000)}) exten => whois,1,NoOp()
same => n,TrySystem(/var/lib/asterisk/scripts/jerry/whois.py "${USERINPUT}" "${SESSIONUNID}") same => n,TrySystem(/var/lib/asterisk/scripts/jerry/whois.py "${USERINPUT}" "${UNIQUEID}")
same => n,Playback(/var/tmp/ast-dynamic/${SESSIONUNID}) same => n,Playback(/var/tmp/ast-dynamic/${UNIQUEID})
same => n,GotoIf($["${PLAYBACKSTATUS}" = "SUCCESS"]?whois,whoisend:) same => n,GotoIf($["${PLAYBACKSTATUS}" = "SUCCESS"]?whois,whoisend:)
same => n,Playback(im-sorry&something-terribly-wrong) same => n,Playback(im-sorry&something-terribly-wrong)
same => n(whoisend),Goto(s,1) same => n(whoisend),Goto(s,1)
[extmymenu] [extmymenu]
exten => _X.,5,Set(CALLNUM=${EXTEN}) exten => _X!,200,Set(CALLNUM=${EXTEN})
same => n,Goto(s,1) same => n,Goto(s,1)
exten => _X!,210,Set(CALLNUM=${EXTEN})
same => n,Goto(3,1)
exten => s,1,Wait(1) exten => s,1,Wait(1)
same => n(loop),Background(jerry-intro) same => n(loop),Background(jerry-intro)
same => n,WaitExten(15) same => n,WaitExten(15)
@ -40,7 +43,7 @@ exten => _X,1,NoOp()
same => n,Goto(s,loop) same => n,Goto(s,loop)
exten => 1,100,NoOp() exten => 1,100,NoOp()
same => n,Goto(extdn42whois,${CALLNUM},5) same => n,Goto(extdn42whois,${CALLNUM},200)
same => n,Return() same => n,Return()
exten => 2,100,NoOp() exten => 2,100,NoOp()
@ -51,7 +54,7 @@ exten => 3,100,NoOp()
same => n,Playback(your&number&is) same => n,Playback(your&number&is)
same => n,SayAlpha(${CALLERID(num)}) same => n,SayAlpha(${CALLERID(num)})
same => n,Playback(silence/1&calling) same => n,Playback(silence/1&calling)
same => n,SayAlpha(${CALLNUM}) same => n,SayAlpha(42403618${CALLNUM})
same => n,Return() same => n,Return()
exten => 4,100,NoOp() exten => 4,100,NoOp()
@ -73,41 +76,42 @@ exten => i,1,NoOp()
exten => chanunavail,1,Playback(im-sorry&number-not-answering&please-try-call-later) exten => chanunavail,1,Playback(im-sorry&number-not-answering&please-try-call-later)
same => n,Hangup() same => n,Hangup()
exten => 424036180001,5,Dial(PJSIP/REDACTED,300,m) exten => invalidinput,1,Playback(im-sorry&cannot-complete-as-dialed)
exten => 424036180002,5,Dial(PJSIP/REDACTED,300,m) same => n,Hangup()
exten => 424036180003,5,Dial(PJSIP/REDACTED,300,m)
exten => 424036180004,5,Dial(PJSIP/REDACTED,300,m) exten => 0001,5,Dial(PJSIP/REDACTED,300,m)
exten => 424036180005,5,Dial(PJSIP/REDACTED,300,m) exten => 0002,5,Dial(PJSIP/REDACTED,300,m)
exten => _X.,6,GotoIf($["${DIALSTATUS}" = "CHANUNAVAIL"]?chanunavail,1:) exten => 0003,5,Dial(PJSIP/REDACTED,300,m)
exten => 424036180000,5,Goto(extmymenu,${EXTEN},5) exten => 0004,5,Dial(PJSIP/REDACTED,300,m)
exten => 424036183618,5,Playback(silence/1&your&number&is) exten => 0005,5,Dial(PJSIP/REDACTED,300,m)
same => n,SayAlpha(${CALLERID(num)}) exten => 0000,5,Goto(extmymenu,${EXTEN},200)
same => n,Playback(silence/1) exten => 0 ,5,Goto(extmymenu,${EXTEN},200)
exten => 424036184242,5,Goto(extdn42whois,${EXTEN},5) exten => 3618,5,Goto(extmymenu,${EXTEN},210)
exten => _42403618XXXX,5,Playback(im-sorry&check-number-dial-again) exten => 4242,5,Goto(extdn42whois,${EXTEN},200)
exten => _X! ,5,Playback(im-sorry&check-number-dial-again)
exten => _X! ,6,GotoIf($["${DIALSTATUS}" = "CHANUNAVAIL"]?chanunavail,1:)
[extpeers] [extpeers]
exten => _42403618XXXX,5,Answer() exten => _42403618.,5,Answer()
same => n,Goto(extmyself,${EXTEN},5) same => n,GotoIf($["${EXTEN:8}" : ".*[^0-9]+.*"]?extmyself,invalidinput,1:)
same => n,Goto(extmyself,${EXTEN:8},5)
exten => _42401332XXXX,5,NoOp() exten => _42401332.,5,NoOp()
same => n,Dial(PJSIP/${EXTEN}@nia) same => n,Dial(PJSIP/${EXTEN}@nia)
exten => _42403315XXXX,5,NoOp() exten => _42403315.,5,NoOp()
same => n,Dial(PJSIP/${EXTEN}@zane) same => n,Dial(PJSIP/${EXTEN}@zane)
exten => _42403088XXXX,5,NoOp() exten => _42403088.,5,NoOp()
same => n,Dial(PJSIP/${EXTEN}@sunnet) same => n,Dial(PJSIP/${EXTEN}@sunnet)
exten => _42401353XXXX,5,NoOp() exten => _42401353.,5,NoOp()
same => n,Dial(PJSIP/${EXTEN}@hertz) same => n,Dial(PJSIP/${EXTEN}@hertz)
exten => _42400119XXXX,5,NoOp() exten => _42400119.,5,NoOp()
same => n,Dial(PJSIP/${EXTEN}@jrb0001) same => n,Dial(PJSIP/${EXTEN}@jrb0001)
[jerry] [jerry]
exten => _XXXX,1,Goto(42403618${EXTEN},1) exten => _4240XXXX.,1,Goto(extpeers,${EXTEN},5)
exten => _XXXXXXXX,1,Goto(4240${EXTEN},1) exten => _0XXXX. ,1,Goto(extpeers,424${EXTEN},5)
exten => _X.,1,NoOp() exten => _X! ,1,Goto(extpeers,42403618${EXTEN},5)
exten => _X.,2,Goto(extpeers,${EXTEN},5)

View file

@ -136,6 +136,7 @@ match=172.20.29.73
[jrb0001](endpoint-template) [jrb0001](endpoint-template)
aors = jrb0001 aors = jrb0001
identify_by=ip identify_by=ip
allow=!all,opus48,opus,ulaw,speex,alaw
[jrb0001](aor-template) [jrb0001](aor-template)
contact=sip:[fd42:5d71:219:1003:216:3eff:fe9d:882f]:5060 contact=sip:[fd42:5d71:219:1003:216:3eff:fe9d:882f]:5060
[jrb0001] [jrb0001]

View file

@ -15,8 +15,11 @@ ROOTDIR = Path("/var/tmp")
OUTDIR = ROOTDIR / "ast-dynamic" OUTDIR = ROOTDIR / "ast-dynamic"
OUTDIR.mkdir(exist_ok=True) OUTDIR.mkdir(exist_ok=True)
def cleanup(): def cleanup(*files):
try: try:
for f in files:
if f.exists():
f.unlink()
now = time() now = time()
for f in OUTDIR.iterdir(): for f in OUTDIR.iterdir():
if f.is_file() and now - f.stat().st_mtime > 60.0: if f.is_file() and now - f.stat().st_mtime > 60.0:
@ -24,7 +27,7 @@ def cleanup():
except Exception: except Exception:
raise raise
def espeak(to_speak, unid): def espeak(to_speak, outfile):
p1 = subprocess.run( p1 = subprocess.run(
["espeak-ng", "-v", "en-us", "--stdin", "-p", "80", "--stdout"], ["espeak-ng", "-v", "en-us", "--stdin", "-p", "80", "--stdout"],
input=str(to_speak).encode("utf-8"), input=str(to_speak).encode("utf-8"),
@ -32,10 +35,8 @@ def espeak(to_speak, unid):
check=True, check=True,
timeout=10 timeout=10
) )
unfile = f"{unid}.wav"
p2 = subprocess.run(['ffmpeg', '-hide_banner', '-i', "-", p2 = subprocess.run(['ffmpeg', '-hide_banner', '-i', "-",
'-vn', "-ac", "1", "-ar", "8000", "-y", "-vn", "-ac", "1", "-ar", "8000", f"{outfile}"],
f"{OUTDIR / unfile}"],
input=p1.stdout, input=p1.stdout,
capture_output=True, capture_output=True,
check=True, check=True,
@ -123,15 +124,17 @@ def whois(arg):
def main(): def main():
# argv[1]: as number # argv[1]: as number
# argv[2]: unique identifier # argv[2]: unique identifier
cleanup() unid = argv[2]
outfile = OUTDIR / f"{unid}.wav"
errfile = OUTDIR / f"{unid}{ERRSOUND.suffix}"
cleanup(outfile, errfile)
try: try:
ret = whois(argv[1]) ret = whois(argv[1])
except Exception as e: except Exception as e:
ret = f"error, {e}" ret = f"error, {e}"
try: try:
espeak(ret, argv[2]) espeak(ret, outfile)
except Exception: except Exception:
outpath = OUTDIR / f"{argv[2]}{ERRSOUND.suffix}" shutil.copy(ERRSOUND, errfile)
shutil.copy(ERRSOUND, outpath)
if __name__ == "__main__": if __name__ == "__main__":
main() main()