1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

PIONEERS Facebook Messenger Webhooks

Discussion in 'Developers' Corner' started by ABSGINC, Sep 16, 2017.

?

DO YOU HAVE FACEBOOK MESSENGER INSTALLED ON YOUR MOBILE DEVICE?

  1. YES

  2. NO

Results are only viewable after voting.
  1. wardmundy

    wardmundy Nerd Uno

    Joined:
    Oct 12, 2007
    Messages:
    13,819
    Likes Received:
    2,293
    Traditional SMS Messaging with Facebook Messenger

    [​IMG]

    We've implemented a new SMS function in the latest build.

    Syntax in Messenger:
    Code:
    sms 10-digit-SMS-number "Some message"
    This requires a working Google Voice account and a working pygooglevoice implementation on an Incredible PBX platform. Google Voice need not be installed in Incredible PBX. You just need an account.

    After installing the latest build from above, insert your Google Voice credentials for a working Google Voice account in .smssend. Then test the SMS functionality by issuing the following command from the Linux CLI:

    Code:
    /var/www/html/fb/.smssend 10-DIGIT-SMS-NUMBER "This is a test"
    If the command fails, follow the instructions on the screen and immediately try again. Google has gotten picky about plain-text passwords. If you try several times with no success even after enabling the Google Voice password relaxer, then you might try reinstalling the latest pygooglevoice from here.

    Until you get this working from the command line, the SMS command in Messenger won't work.
     
    #61 wardmundy, Sep 27, 2017
    Last edited: Sep 28, 2017
  2. ABSGINC

    ABSGINC You can call me Scott.

    Joined:
    Oct 1, 2014
    Messages:
    47
    Likes Received:
    21
    That is very cool, never ceases to amaze me the possibilities.. @wardmundy & @Sylvain Boily have continued to provide great base examples in this proof of concept in communicating quickly with our PBX's. Thank you both very much! All open source and free so long as Facebook keeps it plugged in. I'm sure it will be just fine, withstanding possible version updates of facebooks graph api's, though this one seems like it will be around for at least a few years before depreciated as it's chat was just superseded by what were using now.

    Time to get busy!
     
  3. wardmundy

    wardmundy Nerd Uno

    Joined:
    Oct 12, 2007
    Messages:
    13,819
    Likes Received:
    2,293
    Hopefully, this will be the last manual update you ever have to apply. There's a new update command which, after loading today's release, will do all of the heavy lifting for you.

    1. To get current, protect your existing config files and settings with chattr:
    Code:
    cd /var/www/html/fb
    mv smssend .smssend
    chattr +i  cli-message.php
    chattr +i  config.inc.php
    chattr +i .smssend
    chattr +i .cli-call
    
    2. Then download and install the latest tarball following the previous instructions.

    3. If your FB Messenger implementation is not stored in /var/www/html/fb, edit .update and insert the correct directory to match your location.

    4. Reset the chattr settings to default and reset fb directory ownership and permissions:
    Code:
    cd /var/www/html/fb
    chattr -i  cli-message.php
    chattr -i  config.inc.php
    chattr -i .smssend
    chattr -i .cli-call
    chown -R asterisk:www-data /var/www/html/fb
    chmod -R 775 /var/www/html/fb
    
    After you get today's update installed, you can load new updates by typing update in Facebook Messenger. It won't hurt to run it more than once.

    [​IMG]
     
    #63 wardmundy, Sep 28, 2017
    Last edited: Sep 29, 2017
  4. wardmundy

    wardmundy Nerd Uno

    Joined:
    Oct 12, 2007
    Messages:
    13,819
    Likes Received:
    2,293
    Just want to raise a SPECIAL ALERT FLAG FOR WAZO admins (only) integrating Facebook Messenger with your PBX. For whatever reason, Wazo runs some apps as asterisk and others (such as NGINX web server) as www-data. This differs from other deployments such as Incredible PBX and Issabel that run all tasks as asterisk. Normally, this doesn't cause problems on Asterisk platforms because the file owner/creator has read, write, and execute permissions. But, when you are integrating Webhooks into Asterisk servers running Wazo, it can be a headache if you're not careful about file permissions.

    When new files are created, the default permissions are typically 755 or 744 meaning the Group account does not have write permissions to the files. In the Wazo design, www-data is the Group account holder which means that Messenger Webhooks cannot write or overwrite files unless you alter the file permissions outside of the webhooks environment, i.e. as the root user. This could be a major headache now that we have incorporated an update utility in the software because it would mean that attempts to replace index.php would fail unless you set the permissions on the fb directory and files correctly on the Wazo platform (only) to begin with. Here's how:

    Code:
    chown -R asterisk:www-data /var/www/html/fb
    chmod -R 775 /var/www/html/fb
    
    As part of the update process, since webhooks is operating as www-data user with Wazo, it means new files created as part of the update procedure will have www-data ownership. Therefore, we will make asterisk the group owner on the newly created files. This preserves the Wazo scheme, just backwards, while preserving the asterisk group setting used on other platforms. These generic commands will work on ALL platforms for newly created files generated by webhooks:
    Code:
    chown :asterisk index.php
    chmod 775 index.php
    
     
    #64 wardmundy, Sep 29, 2017
    Last edited: Sep 29, 2017
  5. krzykat

    krzykat Guru

    Joined:
    Aug 2, 2008
    Messages:
    1,258
    Likes Received:
    300
    Hey - make this work with the SMS messaging from VoIP Innovations and I'll help sponsor your trip
     
  6. wardmundy

    wardmundy Nerd Uno

    Joined:
    Oct 12, 2007
    Messages:
    13,819
    Likes Received:
    2,293
    @krzykat: Did you look at our .smssend script. There's only one line of bash code for Google Voice SMS messaging. Should be about the same for any other provider:
    Code:
    if [ -z "$2" ]; then
     echo 'Syntax: smssend 10-DIGIT-SMSNUMBER "SMS Message enclosed in quotes"'
     exit 0
    fi
    
    SMSNUM=$1
    SMSMSG=$2
    
    
    echo "Sending SMS message to: $SMSNUM"
    gvoice -e $GVACCT -p $GVPASS send_sms $SMSNUM "$MSGSUBJECT: $SMSMSG"
    
    
    [​IMG]

    [​IMG]

    And here's the PHP code for VoIP.ms SMS messages after adding their class.voipms.php component to the same directory:

    Code:
    $voipms = new VoIPms();
    
    /* Send SMS */
    $response = $voipms->sendSMS($SMSsender,$smsnumber,$smsmessage);
    
    
     
    #66 wardmundy, Sep 30, 2017
    Last edited: Sep 30, 2017
  7. wardmundy

    wardmundy Nerd Uno

    Joined:
    Oct 12, 2007
    Messages:
    13,819
    Likes Received:
    2,293
    #67 wardmundy, Sep 30, 2017
    Last edited: Sep 30, 2017
  8. wardmundy

    wardmundy Nerd Uno

    Joined:
    Oct 12, 2007
    Messages:
    13,819
    Likes Received:
    2,293
    Enhanced Call Option. Beginning with the October 1 update which you can obtain by entering the update command in Messenger, you now have two calling options on some smartphone platforms. The call command still triggers an AsteriDex lookup on your PBX. But now... (1) you can click the dial button to place the outbound call through your PBX, or (2) you can click on the retrieved phone number link to place the outbound call using the client-side resource available on your mobile phone's Messenger platform, e.g. Facetime, Skype, or Google Hangouts. Depending upon your location, the second option may be preferable so long as it is a free call.

    [​IMG]
     
  9. krzykat

    krzykat Guru

    Joined:
    Aug 2, 2008
    Messages:
    1,258
    Likes Received:
    300
    Just thought of another excellent application of this. Conference room - alert who has arrived, left, and user count. You could even reply back "Freeze" to freeze the conference from any new users.
     
    ABSGINC and wardmundy like this.
  10. wardmundy

    wardmundy Nerd Uno

    Joined:
    Oct 12, 2007
    Messages:
    13,819
    Likes Received:
    2,293
    FYI: You can control a number of ConfBridge functions for the Incredible PBX 2663 conference already using the ! shell command:

    Code:
    !asterisk -rx "confbridge [command] 2663"
    Available commands are documented here.
     
    ABSGINC likes this.
  11. krzykat

    krzykat Guru

    Joined:
    Aug 2, 2008
    Messages:
    1,258
    Likes Received:
    300
    @wardmundy Is there going to be any ready made integrations for this with the new Incredible 13-13 ??
     
    ABSGINC likes this.
  12. wardmundy

    wardmundy Nerd Uno

    Joined:
    Oct 12, 2007
    Messages:
    13,819
    Likes Received:
    2,293
    Just obtain your SSL certificate and then follow the existing tutorial here. Skip the first 6 Security steps which already are in place. Edit /usr/local/sbin/iptables-custom and uncomment the last 3 lines in the file. Then iptables-restart. Perform steps #7a and #9. Assuming the test shows your HTTPS is working properly, continue on with:

    1. Installing Incredible PBX Webhooks Application

    2. Hooking Up with Facebook

    3. Outbound Call Setup for Facebook Messenger

    4. Incoming Call Alerts with Facebook Messenger




     
    ABSGINC likes this.
  13. Jose Pinto

    Jose Pinto Member

    Joined:
    Oct 26, 2017
    Messages:
    144
    Likes Received:
    19
    @wardmundy
    Hi I would like to ask you what PBX is better to start this Project, as I would like to work with Incredible PBX it will be better with the upgrade Enchilada or without the upgrade?
    Thank you very much for your time attention and help.
     
  14. trice001

    trice001 New Member

    Joined:
    Wednesday
    Messages:
    1
    Likes Received:
    0
  15. wardmundy

    wardmundy Nerd Uno

    Joined:
    Oct 12, 2007
    Messages:
    13,819
    Likes Received:
    2,293
    Enchilada provides enhancements. It doesn't limit functionality in any way.
     
    Jose Pinto likes this.

Share This Page