Asterisk-phone-reminder: Unterschied zwischen den Versionen

Aus LaborWiki
Wechseln zu: Navigation, Suche
K (added infobox, added css)
Keine Bearbeitungszusammenfassung
 
(7 dazwischenliegende Versionen von 3 Benutzern werden nicht angezeigt)
Zeile 1: Zeile 1:
{{ProjektInfoBox
{{ProjektInfoBox
|name       =  
|name=Asterisk-phone-reminder
|status     = stable
|status=stable
|image       = Oldphone.jpg
|image=Oldphone.jpg
|description = A bot to remind us to take out the trash
|description=A bot to remind us to take out the trash
|username    = Soeren
|author=Soeren
|version    =
|platform=Linux
|update      =
|tags=Labor Infrastruktur,
|platform   = Linux
|update=
|license    =  
|download    =
}}
}}
'''What if your phone could remind you to take out the trash..?''' This is a nice feature, especially for a hackerspace where many people come, leave and nobody is keen on taking responsibility for this kind of task. The following describes our current implementation of a task-reminding telephone bot utilizing asterisk.
'''What if your phone could remind you to take out the trash..?''' This is a nice feature, especially for a hackerspace where many people come, leave and nobody is keen on taking responsibility for this kind of task. The following describes our current implementation of a task-reminding telephone bot utilizing asterisk.
Zeile 77: Zeile 75:
----
----
''...for those of you sitting in the labor now with that evil smile on your face, here's a short warning: '''Don't abuse this feature. Do NOT set alarms unless really neccessary. People will ignore the phone when they're called just for a joke.''' If you really want to try out what it does, simply dial 7700 or 7701.''
''...for those of you sitting in the labor now with that evil smile on your face, here's a short warning: '''Don't abuse this feature. Do NOT set alarms unless really neccessary. People will ignore the phone when they're called just for a joke.''' If you really want to try out what it does, simply dial 7700 or 7701.''
----
[[Asterisk-phone-reminder/Date-fetching|Automatically fetching dates for the Trash]]


[[category:Automatisierung]] [[category:Technische Dokumentation]] [[category:Infrastruktur]]
[[category:Automatisierung]] [[category:LaborOrga]] [[category:Infrastruktur]]

Aktuelle Version vom 8. April 2017, 00:22 Uhr

     
Asterisk-phone-reminder

Release status: stable [box doku]

Datei:Oldphone.jpg
Description A bot to remind us to take out the trash
Author(s)  Soeren
Platform  Linux



What if your phone could remind you to take out the trash..? This is a nice feature, especially for a hackerspace where many people come, leave and nobody is keen on taking responsibility for this kind of task. The following describes our current implementation of a task-reminding telephone bot utilizing asterisk.

The asterisk phone reminder is a simple tool that calls you before an "important" event occurs. Asterisk allows to place "call files" into a spool-directory. It scans that directory regularly and parses the timestamps of the files therein. If a file's timestamp is older than the present time, it executes the commands within the file.

This project uses this feature in order to set the reminders. A small perl script looks into a directory (/etc/labor-task-reminder/dates) and copies a predefined call file into asterisk's spool directory if there's a file with a date that's < 30 Hours ahead. Well, here it goes:

#!/usr/bin/perl
use POSIX qw(mktime);

# config stuff:
$dpath = "/etc/labor-task-reminder/dates/"; # path for dates
$cfpath = "/etc/labor-task-reminder/callfiles/"; # path for cfiles, mind the slash at the end!
$spoolpath = "/var/spool/asterisk/outgoing/";   # asterisk's call spool
$remindtime = 108000;  # time (in seconds) to start the reminder  (10800 == 30 hours before)

@dfiles = `ls --color=never $dpath`;
foreach $dfile (@dfiles)
{
       if ( ! $dfile =~ m/^(20[0-9]{2})-([0-9]+)-([0-9]+)-.*\$/ ) { next; }
       $dfile =~ /^(20[0-9]{2})-([0-9]+)-([0-9]+)-(.*)$/;
       my($foo) = mktime(0,0,0, $3, $2 -1, $1 - 1900, 0, 0, -1);
       $foo -= $remindtime;
       if ($foo < time())
       {
               if (-e "${cfpath}${4}")
               {
                       system("cp ${cfpath}${4} ${spoolpath}");
                       system("rm ${dpath}${dfile}");
               }
       }
}

This script is called once a day by cron - with a 30-hour treshold this should be sufficient to remind soon enough the day before the trash is taken away.

As mentioned before, the path /etc/labor-task-reminder/dates holds several files with dates as their names. These files are, for example, called "2009-01-30-altpapier". The last word of the filename is the name of the callfile that is then placed into asterisk's spool. A set of predefined callfiles resides in /etc/labor-task-reminder/callfiles. Here's an example file called "gelbersack":

Channel: SIP/0000
Callerid: 1337
MaxRetries: 2000
RetryTime: 600
WaitTime: 60
Context: reminders
Extension: 7700

The file's parameters have the following meaning:

  • Call SIP/0000 (this is the extension to call when you want to reach all phones)
  • Callerid: Set the callerid "1337" ;-)
  • Maxretries: Try 2000 times...
  • Retrytime: ...every 600 seconds...
  • WaitTime: ...and let the phone ring for 60 seconds.
  • Context: Well, guess what! The context.
  • Extension: Right, the extension to run

If you've dealt with asterisk before, you probably know that we'll also have to edit extensions.conf in order to make this work. The context and extension have to be added so asterisk knows what to do. Well, our extensions.conf looks like this:

; ...
[reminders]
exten => 7700,1,Answer()
exten => 7700,n,Wait(2)
exten => 7700,n,Playback(gelbersack)
exten => 7700,n,Wait(1)
exten => 7700,n,Hangup()
; ...

...for those of you sitting in the labor now with that evil smile on your face, here's a short warning: Don't abuse this feature. Do NOT set alarms unless really neccessary. People will ignore the phone when they're called just for a joke. If you really want to try out what it does, simply dial 7700 or 7701.


Automatically fetching dates for the Trash