9

Old days many admins use sms-gates for sending important informations from their systems e.g. "Power down, UPS is working now!", "Power Up, UPS is off!" or "CPU Temp too high!". Today in Facebook era we use messenger instead of SMS, so I wonder if I could create a command-line bash or php script for such thing.

The idea - cron checks every 10 minutes the condition and if it is true, sends message to my messenger.

The issues:

  1. I don't want to use my fb account for sending - I'd like to get message from "System 1", "System 2", because i have more than one system to admin.
  2. The bash part is easy for me, I need tips for Facebook solutions:
    • do I have to get FacebookAppId (and do I have to create AppId for each system or just one AppId)
    • how to "join/confirm/accept" "System 1" account with my Facebook Account
    • is it possible to send messages to more than one FBAccount
    • any other hints what should i look for.

I found Notification App, but i think that it doesn't send message to messenger, so it would be useless.

Tomasz Brzezina
  • 1,452
  • 5
  • 21
  • 44
  • I thought Facebook had a system where you could update your status via email? If so, why not do that (but limit your posts to a specific audience first [aka, you])? You can then subscribe to the account and receive notifications when there is a new update. Unfortunately it's against Facebook's rules to have many dummy accounts, but as far as I know they do allow an extra account for developers; you could append 'Server 1', "Server 2", etc. in the status update. – AStopher May 15 '15 at 08:09
  • 1
    no, they do NOT allow and extra account for developers. and updating your status so every friend sees it may be a very bad idea. it´s a warning for yourself only. – andyrandy May 15 '15 at 09:54

6 Answers6

6

The Chat API was removed with v2.0 of the Graph API, there is no way to send messages with an API anymore. Btw, messages are for communcation between real users, they should not be used as notification system anyway. SMS is still a good option for those kind of warnings imho.

Using a Page and the /conversations endpoint would not work either:

Pages can only reply to a message - they cannot initiate a conversation. Also, a Page can only respond twice to a particular message, the other party will have to respond before they can reply again.

Source: https://developers.facebook.com/docs/graph-api/reference/v2.3/conversation/messages#publish

andyrandy
  • 72,880
  • 8
  • 113
  • 130
  • SMS are paid or limited 10/month for example and so easy to implement command-line - so I'm looking for cheaper alternative (10/day or more). But I don't understand why messages are for communication between real users only - is this in FB policy? – Tomasz Brzezina May 15 '15 at 09:57
  • 1
    it´s common sense :) - and yes, it is actually in the policy too. even if the chat api would still exist, every single message would have to be 100% user generated and fake accounts are not allowed. you would have to create a fake/developer account to send yourself messages > not allowed. – andyrandy May 15 '15 at 10:01
  • What about page account? I can't check it now if I can send message as a page not user – Tomasz Brzezina May 15 '15 at 10:11
  • 1
    you can only reply to comments, you can´t initiate messages as page. it´s all in the facebook docs. i´ve added the relevant parts to my answer. – andyrandy May 15 '15 at 10:11
2

I think for your special purpose, twitter may be a better option. Twitter accepts tweets from API. So what you need to do is to set up an account to publish your system status either regularly or event-triggingly and follow it in your own personal account. And there are already plenty of open source projects focusing on tweeting via API, and t is the one I am currently using.

hzh
  • 342
  • 2
  • 15
1

So there are a couple of command line apps to do this.

There is a libpurple extension (https://github.com/dequis/purple-facebook) which works. However purple doesn't seem to support the idea of message history. This is a shame since I imagine offline messages is the default way most people use facebook.

There is an single use command tool for facebook as well: https://www.npmjs.com/package/fb-messenger-cli which does support history. Unfortunately this is a TUI rather than a command line application and doesn't seem to depend on a separate facebook library. Some hacking or terrible expect glue could work around this.

Att Righ
  • 1,439
  • 1
  • 16
  • 29
1

I just published a service exactly for that use case : https://www.nimrod-messenger.io/

It's at an early stage. Feedbacks are more than welcome :-)

xurei
  • 1,057
  • 8
  • 22
  • This is amazing solution ONLY to yourself. What if I would like to send such message to multiple users? – Erikas Aug 12 '17 at 16:44
  • You can send this message multiple times to multiples people. You just need their API key to do that. Would you be interested in a solution where just one API call would be required ? It will need some extra configuration, obviously. – xurei Apr 24 '18 at 13:51
  • 1
    I don't know how the public feels about that, but personally I would hesitate sending any information through a proxy belonging to a person I know nothing about. And by "hesitate" I mean "I would never do it, ever". – Robert Synoradzki Nov 13 '18 at 10:06
0

Sending facebook message in bash script

IDEA

I needed a script (which work on my work/local mac) that checks server. If there are problems, script will send me messages on Facebook.

Dependencies

need to install: https://github.com/mjkaufer/Messer

Solution, bash script

FB_SENDER_LOGIN=""
FB_SENDER_PASSWORD=""

function send_fb_message {
    FB_MESSER_COMAND="messer $FB_SENDER_LOGIN $FB_SENDER_PASSWORD --command='m \"$1\" $2'"
    eval "$FB_MESSER_COMAND"
}

RECIPIENT_NAME_DISPLAYED_IN_FACEBOOK_WEBSITE="Vasily Bodnarchuk"
MESSAGE="Houston, we have a problem!!!"
send_fb_message "$RECIPIENT_NAME_DISPLAYED_IN_FACEBOOK_WEBSITE" "$MESSAGE"
Vasily Bodnarchuk
  • 24,482
  • 9
  • 132
  • 127
0

Automated Facebook message

I was looking for something like this exactly and found that Messer is the way to go.

Solution

Look at this repo called Messer https://github.com/mjkaufer/Messer
(it works with 2FA too but not with app passwords)

Implementation

  1. See Readme

  2. I needed it to run automatically so I used it's non-interactive mode with a bash script:

message="Hey, what\'s up bro"
FULLPATH/node_modules/.bin/messer --command="m \"Myfriends Name\" $message"
  • I don't like to install something like this globally through NPM so I used the /node_modules/.bin/messer executable in the project's folder.
  • Used double quotes escaped instead of single quotes to be able to use variables inside command.
  • Drawback: Messer can only send, not receive.
double-beep
  • 5,031
  • 17
  • 33
  • 41