Menu

Execute shell script when receiving a call?

nospam
2015-03-27
2016-09-20
  • nospam

    nospam - 2015-03-27

    Does ncidd support executing a shell script when it receives a call? I was considering having my ncidd server SMS me the phone number whenever I miss a call.

     
    • BTodCox

      BTodCox - 2015-03-28

      You can use ncid-notify to get real time NCID messages on a smartphone. It works well with Notify My Android on Android phones and Prowl on iOS devices.

       
  • Chris Lenderman

    Chris Lenderman - 2015-03-27

    NCIDD doesn't but NCID for Linux does. Or if you have an Android phone, you can receive notifications of your home calls on your Android device by using NCID Android.

    Here is how I execute a shell script using NCID for Linux to execute a shell script: ncid --no-gui --ring 2 --program ncid-um &

    Then I put a script called ncid-um into /usr/share/ncid

    I am running Fedora Linux. Instructions may vary based on your operating system. But the key thing is that the capability is there.

     
  • nospam

    nospam - 2015-03-27

    Thanks. I am running ncidd on a raspberry Pi. Am I assuming correctly that I can run NCID client on the same Pi and have it execute the script?

     
  • Chris Lenderman

    Chris Lenderman - 2015-03-27

    Very good question. I am not sure, but I know someone who is :-) Todd/John have you tried this?

     
  • BTodCox

    BTodCox - 2015-03-28

    In fact, you can run multiple instances of NCID on the same RPi that is running NCIDD. Each instance of NCID is just another client as far as NCIDD is concerned.

    Tod

     
  • John L. Chmielewski

    You might want to check out the following output modules in /usr/share/ncid:

    ncid-page:   sends a SMS message to your phone
    ncid-notify: sends a notification to your phone using either NMA or Prowl
    ncid-skel:   sample output module for creating your own module
    

    All output modules are shell scripts and you can review any of them. Comments at the beginning explain usage. There is also a man page for each module.

    There are more modules but you should get the source to review all there is.

     
  • Todd Andrews

    Todd Andrews - 2015-04-09

    Hi nospam,

    FYI, my cell phone carrier is T-Mobile and I've found that it generally takes seconds-to-minutes longer for ncid-page notifications to arrive on my cell. I've been using ncid-notify (specifically, Notify My Android) to get near real-time notifications.

     
  • nospam

    nospam - 2016-09-15

    Hi Todd

    I'm looking into possibly modifying ncid-notify.conf to use the Telegram messanger app (https://telegram.org) to deliver call notifications. The reason for this is that I'm finding a delay taking up to 2-3 rings before ncidpop displays the info whereas Telegram will display messages on all my clients simultaneously and is faster. Secondly, I want to be able to filter certain messages and have them forwarded to my android device. Due to my ISP using NAT I cannot access my network from the internet ie. cell phone.

    I want to filter and parse the CID numbers to quickly flag SPAM callers during certain times of day and to send special notifications based on the incomming CID.

    I am running a telegram client on my NCIDD server and can send a message using the command line in the following format

    telegram-cli -W -e "msg @user this is my message ###-###-### callerid info here"
    

    Do you have any suggestions to using one of your scripts to run a shell script by modifying one of your output modules?

     
  • Todd Andrews

    Todd Andrews - 2016-09-16

    Hi nospam,

    1. The 2-3 ring delay before NCIDpop displays the info is very concerning because we've always tried to make caller ID delivery as quick as possible. We'd be grateful if we could work with you to figure out why this is happening, if you had the time. For example, do you have a lot of clients connecting to ncidd? (If you issue the command sudo pkill -s usr2 ncidd it will display all connected clients in ncidd.log; it won't terminate ncidd.) Another factor would be the order that NCIDpop appears in the connected client list -- data is sent in the order listed. Running ncidd at minimum verbose level 6 will show timestamps for most activity.

    2. Telegram looks fantastic -- I read most of their docs. We might be able to take advantage of their API and create an interface to NCID but for now I'm attaching a custom output module and config file that you can try based on your telegram-cli example above. Put ncid-telegram.conf in the same directory where you have ncid-notify.conf, and put ncid-telegram in the same directory where you have ncid-notify. Modify ncid-telegram.conf to specify the telegram user, and modify ncid-telegram to set ConfigDir to your path containing ncid-telegram.conf. Test launch it with ncid --no-gui --program ncid-telegram.

    (Edited by me to add how to launch it.)
    (Updated 09/17/16 with revised ncid-telegram attachment to fix quotes bug)

     

    Last edit: Todd Andrews 2016-09-17
  • nospam

    nospam - 2016-09-16

    Awesome thanks! I will give it a try.

    I've been using Telegram for security camera notifications for a little while now and am pleased with it so far.

    I only have one ncidpop client running on OSX and I'm finding it sluggish after the last upgrade to ncidd and ncidpop. I'm running ncidd on a RPi 3 with tons of free storage space on a fast SD card.

    One wish I have with ncidpop is an option to eliminate all the confirmation popup messages when adding or updating aliases

    "Would you like to apply aliases to all call logs"
    Then message "ReceivedSignal..."
    then I have to wait about 30-60s for the third popup
    "Accept Changes"

    In terms of update speed I'm finding using my PHP script to display callerid info updates by the second ring. ncidpop is taking up to the fourth ring at times. nicidpop is especially slow after resuming OSX from sleep so it may be an OSX El Crapitan issue.

     
    • BTodCox

      BTodCox - 2016-09-16

      nospam,
      OSX is the most likely source of your delayed notifications in NCIDpop. I run NCIDpop on a couple of different Macs and I have seen the delayed notification that you mention. They are both connected to my home network via wifi.

      Here's my rationale for claiming OSX is the likely culprit:
      I have ncid setup to sniff SIP packets (Vonage), so I obtain caller ID info before the first ring. I have multiple NCIDdisplay devices that always display CID info just before or coincident with the first ring as expected with my setup. It is not unusual for the NCIDpop to be delayed on the nofication, particularly on my Mac laptop. Since NCIDpop indicates that it is connected to my ncid server when I am at home, and my NCIDdisplays show the CID very quickly, it seems pretty likely that OSX is the culprit.

      One aspect of delayed notifications that I have not been able to completely rationalize is that I don't see the delay if I am connected to my nodejs ncid client/webserver in a browser on the same Mac. I have never seen a delay in the browser updating the ncidd call info even when there is an NCIDpop delay on the same Mac. The nodejs code uses socket.io for data transfer, so perhaps socket.io utilizes a faster path for the call info packet through the OS to the browser, but that is purely speculation on my part.

       
    • Todd Andrews

      Todd Andrews - 2016-09-18

      Hi nospam,

      Regarding your feature request for the confirmation dialogs, I've created a feature request ticket for you here. It would help in the future if you could create feature requests on your own because it's easy for us as developers to miss requests in long support threads.

      Also, the developer for NCIDpop and NCID Android -- Chris Lenderman -- is currently in the process moving half way across the country in order to start a new job. It may be several weeks before Chris can work on it.

       
  • nospam

    nospam - 2016-09-16

    Hi Todd,

    I tried installing the two files ncid-telegram and ncid-telegram.conf but when I try running it I get the error

    127.0.0.1:3333 - couldn't open socket: connection refused

    and ncidd won't start or run


    maybe I jumped the gun. I did
    pi@RPi3:~ $ sudo invoke-rc.d ncidd stop
    pi@RPi3:~ $ sudo invoke-rc.d ncidd start
    pi@RPi3:~ $ Connected to 127.0.0.1:3333
    Client: ncid (NCID) 1.4.3
    Server: ncidd (NCID) 1.4

    Then I did a test call and got the following text at the command prompt

    pi@RPi3:~ $
    pi@RPi3:~ $ change_user_group: can't find the user telegramd to switch to
    Telegram-cli version 1.4.1, Copyright (C) 2013-2015 Vitaly Valtman
    Telegram-cli comes with ABSOLUTELY NO WARRANTY; for details type show_license'. This is free software, and you are welcome to redistribute it under certain conditions; typeshow_license' for details.
    Telegram-cli uses libtgl version 2.1.0
    Telegram-cli includes software developed by the OpenSSL Project
    for use in the OpenSSL Toolkit. (http://www.openssl.org/)
    I: config dir=[/root/.telegram-cli]
    [/root/.telegram-cli] created
    [/root/.telegram-cli/downloads] created

    [warn] Epoll ADD(1) on fd 0 failed. Old events were 0; read change was 1 (add); write change was 0 (none): Operation not permitted
    phone number:

     

    Last edit: nospam 2016-09-16
  • Todd Andrews

    Todd Andrews - 2016-09-17

    Hi nospam,

    I'm somewhat confused, or maybe I confused you (probably the latter).

    If the server is already running OK, it should not have been necessary to restart the server process with sudo invoke-rc.d .... Nothing about the server running needs to be restarted if all you're going to do is launch a new output module like ncid-telgram.

    If the server is not running, looking at the log file should given an indication as to why it stopped:

    tail -50 /var/log/ncidd.log
    

    To make it clearer, to test the new ncid-telegram script, type this at the command line on your RPi3 that is already running ncidd:

    ncid --no-gui --program ncid-telegram
    

    Note that I didn't put "&" at the end. Leaving it off allows running ncid-telegram in the foreground to show messages to the screen.

    I don't know what would give the error, "change_user_group: can't find the user telegramd to switch to".

    I've started installing telegram on my older RPi running Raspbian Wheezy. It's been compiling for 15 minutes already as I type this and it's not done yet.

     
  • nospam

    nospam - 2016-09-17

    Maybe there was somekind of goofiness going on it seems to be working now I'm getting

    $ncid --no-gui --program ncid-telegram

    Connected to 127.0.0.1:3333
    Client: ncid (NCID) 1.4.3
    Server: ncidd (NCID) 1.4

    I just did a test call but don't see anything on Telegram. Should it show up in the log file?

    Here's the output of tail -50 /var/log/ncidd.log
    Checking Modem Capabilities...
    TTY port changed to RAW mode.
    Modem Initialized
    Modem Identifier: U.S. Robotics 56K FAX USB V1.2.23
    Modem country code: 20 Canada
    Modem Active Profile settings:
    ----Option----- --Setting-- Cmd ----Option----- --Setting-- --Cmd--
    Comm Standard CCITT B0 Answer Ring# 0 S0=000
    Command Echo Enabled E1 Escape Char 43 S2=043
    Speaker Volume Medium L2 CR Char 13 S3=013
    Speaker Control OnUntilCD M1 LF Char 10 S4=010
    Result Codes Enabled Q0 BS Char 8 S5=008
    Dialer Type Tone T/P Dial Pause 3 sec S6=003
    Result Form Text V1 NoAns Timeout 60 sec S7=060
    Extend Result Enabled X4 "," Pause 2 sec S8=002
    DialTone Detect Enabled X4 No CD Disc 2000 msec S10=020
    BusyTone Detect Enabled X4 DTMF Speed 95 msec S11=095
    DCD Action Std RS232 &C1 Esc GuardTime 1000 msec S12=050
    DTR Action Std RS232 &D2 Calling Tone Enabled S35=001
    V22b Guard Tone Disabled &G0 Line Rate 33600 S37=000
    Flow Control Hardware &H1
    Error Control V42,MNP,Bfr &M4
    Compression 44 42b MNP5 &K1
    Modem supports Data Mode
    Modem supports FAX Mode 1
    Modem supports VOICE Mode
    TTY port changed to ICANON mode.
    TTY port changed to RAW mode.
    Modem initialized.
    Modem set for CallerID.
    TTY port changed to ICANON mode.
    CallerID from AT Modem and optional gateways
    Handles modem calls without Caller ID
    Modem used for CallerID and to terminate calls
    Internal Hangup recording file: /usr/share/ncid/recordings/NumberDisconnected.rmd
    TTY port changed to RAW mode.
    Manufacturer: U.S. Robotics
    Modem Voice Sampling Methods:
    128,"8-BIT LINEAR",(7200,8000,11025)
    129,"16-BIT LINEAR",(7200,8000,11025)
    130,"8-BIT ALAW",(8000)
    131,"8-BIT ULAW",(8000)
    132,"IMA ADPCM",(7200,8000,11025)
    Modem Voice Sampling Method selected: AT+VSM=128,8000
    TTY port changed to ICANON mode.
    Internal Hangup Mode = 3: play an announcement then hangup on a blacklisted call
    Network Port: 3333
    Wrote pid 15387 in pidfile: /var/run/ncidd.pid
    End of startup: 09/16/2016 17:39:53
    Client 6 pos 2 removed from poll 09/17/2016 11:09:23

    I used
    $nohup ncid --no-gui --program ncid-telegram &

    and here is the nohup.out output from two test calls

    Connected to 127.0.0.1:3333
    Client: ncid (NCID) 1.4.3
    Server: ncidd (NCID) 1.4
    Telegram-cli version 1.4.1, Copyright (C) 2013-2015 Vitaly Valtman
    Telegram-cli comes with ABSOLUTELY NO WARRANTY; for details type show_license'. This is free software, and you are welcome to redistribute it under certain conditions; typeshow_license' for details.
    Telegram-cli uses libtgl version 2.1.0
    Telegram-cli includes software developed by the OpenSSL Project
    for use in the OpenSSL Toolkit. (http://www.openssl.org/)
    I: config dir=[/home/pi/.telegram-cli]
    > [warn] Epoll ADD(1) on fd 0 failed. Old events were 0; read change was 1 (add); write change was 0 (none): Operation not permitted
    [15 Sep] TELEGRAMUSER ««« History was cleared.
    > FAIL: 38: can not parse arg #1
    All done. Exit
    halt
    Telegram-cli version 1.4.1, Copyright (C) 2013-2015 Vitaly Valtman
    Telegram-cli comes with ABSOLUTELY NO WARRANTY; for details type show_license'. This is free software, and you are welcome to redistribute it under certain conditions; typeshow_license' for details.
    Telegram-cli uses libtgl version 2.1.0
    Telegram-cli includes software developed by the OpenSSL Project
    for use in the OpenSSL Toolkit. (http://www.openssl.org/)
    I: config dir=[/home/pi/.telegram-cli]
    > [warn] Epoll ADD(1) on fd 0 failed. Old events were 0; read change was 1 (add); write change was 0 (none): Operation not permitted
    [12:01] TELEGRAMUSER <<< test cmd line
    > FAIL: 38: can not parse arg #1
    All done. Exit
    halt

    It looks to me that Telegram isn't liking something in the text being sent. Probably a problem with the quotations in the command line. I remember seeing similar issues in a C program I wrote to send commands for a motion sensor and here is an excerpt of what worked for me:

    strcpy(mycmd,"telegram-cli -W -e \"msg @TELEGRAMUSER Motion Detected - ");
    strcat(mycmd,"\"");
    system(mycmd);

    I found debugging some of the telegram-cli errors a little obtuse ;-)

     

    Last edit: nospam 2016-09-19
  • Todd Andrews

    Todd Andrews - 2016-09-17

    You're right about needing to escape the quotes. My bad. I attached a revised ncid-telegram script to my original post.

    Telegram-cli did finally finish compiling last night so I'm going to start testing and hopefully be better able to help.

     
  • nospam

    nospam - 2016-09-19

    OK I just tried your changes and still getting errors.

    pi@RPi3:~ $ cat nohup.out
    Connected to 127.0.0.1:3333
    Client: ncid (NCID) 1.4.3
    Server: ncidd (NCID) 1.4
    Telegram-cli version 1.4.1, Copyright (C) 2013-2015 Vitaly Valtman
    Telegram-cli comes with ABSOLUTELY NO WARRANTY; for details type show_license'. This is free software, and you are welcome to redistribute it under certain conditions; typeshow_license' for details.
    Telegram-cli uses libtgl version 2.1.0
    Telegram-cli includes software developed by the OpenSSL Project
    for use in the OpenSSL Toolkit. (http://www.openssl.org/)
    I: config dir=[/home/pi/.telegram-cli]
    > [warn] Epoll ADD(1) on fd 0 failed. Old events were 0; read change was 1 (add); write change was 0 (none): Operation not permitted
    FAIL: 38: can not parse modifier
    > All done. Exit
    halt

    Again Telegram-cli is not liking something. The error did change a little

     

    Last edit: nospam 2016-09-19
  • Todd Andrews

    Todd Andrews - 2016-09-20

    In case anyone is following this, I'm working with nospam via private email until we can resolve the issues.

     

Log in to post a comment.