def test_vgetty(self): #signal.signal(signal.SIGPIPE, signal.SIG_IGN) os.environ["VOICE_INPUT"] = "0" os.environ["VOICE_OUTPUT"] = "1" os.environ["VOICE_PID"] = str(os.getpid()) os.environ["VOICE_PROGRAM"] = "Vgetty.py" cp = Vgetty.CallProgram() # XXX
def mailmessage(cp): parts = [] # main message text and subject line body = CF.mail.body(line=CF.lines.get(cp._device), caller_id=cp.caller_id, caller_name=cp.caller_name) parts.append(body) subj = CF.mail.Subject(line=CF.lines.get(cp._device), caller_id=cp.caller_id, caller_name=cp.caller_name) # ogg file attachment oggfile = tempfile.NamedTemporaryFile(suffix=".ogg", prefix="voicemail", dir="/var/tmp") Vgetty.rmd2ogg(cp.inname, oggfile.name) oggfile.seek(0) ogg = ezmail.MIMEApplication.MIMEApplication(oggfile.read(), "ogg") ogg["Content-Disposition"] = "attachment; filename=%s" % (os.path.basename(cp.inname.replace("rmd", "ogg")), ) oggfile.close() parts.append(ogg) # mail it! ezmail.mail(parts, subject=subj, To=CF.mail.To)
def mailmessage(cp): parts = [] # main message text and subject line body = CF.mail.body(line=CF.lines.get(cp._device), caller_id=cp.caller_id, caller_name=cp.caller_name) parts.append(body) subj = CF.mail.Subject(line=CF.lines.get(cp._device), caller_id=cp.caller_id, caller_name=cp.caller_name) # ogg file attachment oggfile = tempfile.NamedTemporaryFile(suffix=".ogg", prefix="voicemail", dir="/var/tmp") Vgetty.rmd2ogg(cp.inname, oggfile.name) oggfile.seek(0) ogg = ezmail.MIMEApplication.MIMEApplication(oggfile.read(), "ogg") ogg["Content-Disposition"] = "attachment; filename=%s" % (os.path.basename( cp.inname.replace("rmd", "ogg")), ) oggfile.close() parts.append(ogg) # mail it! ezmail.mail(parts, subject=subj, To=CF.mail.To)
def main(argv): cf = ConfigHolder() cf.VOICEDIR = "/var/spool/voice" cf.MESSAGEDIR = "messages" cf.SPOOLDIR = "incoming" cf.GREETING = "greeting.rmd" cf.LOGFILE = "/var/log/voicemail/voicemail.log" lf = logfile.open(cf.LOGFILE) try: rv = Vgetty.answering_machine(cf, lf) finally: lf.close() return rv
def answering_machine(logfile=None, dtmf_handler=None): global CF greeting = os.path.join(CF.VOICEDIR, CF.MESSAGEDIR, CF.GREETING) cp = Vgetty.BasicCallProgram(logfile=logfile) cp.inname = os.path.join(CF.VOICEDIR, CF.SPOOLDIR, "v-%s.rmd" % (int(time.time()), )) cp.set_dtmf_handler(dtmf_handler) cp.play(greeting) cp.beep() try: cp.record(cp.inname) except VgettyError, err: print >> sys.stderr, "%s: %s" % (time.ctime(), err) cp.beep(6000, 3) cp.close()