bash 如何从 linux 控制台发送 facebook 消息(命令行)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30254407/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 13:00:02  来源:igfitidea点击:

How to send facebook message from linux console (command-line)

linuxfacebookbashcommand-linefacebook-messenger

提问by Tomasz Brzezina

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.

过去,许多管理员使用 sms-gate 从他们的系统发送重要信息,例如“断电,UPS 正在工作!”,“通电,UPS 已关闭!” 或“CPU 温度太高!”。今天在 Facebook 时代,我们使用 Messenger 而不是 SMS,所以我想知道我是否可以为这样的东西创建一个命令行 bash 或 php 脚本。

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

想法 - cron 每 10 分钟检查一次条件,如果为真,则向我的信使发送消息。

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.
  1. 我不想使用我的 fb 帐户发送 - 我想从“系统 1”、“系统 2”接收消息,因为我有多个系统需要管理。
  2. bash 部分对我来说很容易,我需要 Facebook 解决方案的提示:
    • 我是否必须获得 FacebookAppId(我是否必须为每个系统创建 AppId 或仅创建一个 AppId)
    • 如何使用我的 Facebook 帐户“加入/确认/接受”“系统 1”帐户
    • 是否可以向多个 FBAccount 发送消息
    • 任何其他提示我应该寻找什么。

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

我找到了通知应用程序,但我认为它不会向 Messenger 发送消息,因此它没有用。

采纳答案by luschn

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.

Chat API 在 Graph API 的 v2.0 版本中被移除,无法再通过 API 发送消息。顺便说一句,消息是用于真实用户之间的通信,无论如何它们不应该用作通知系统。对于这类警告,恕我直言,短信仍然是一个不错的选择。

Using a Page and the /conversationsendpoint would not work either:

使用 Page 和/conversations端点也不起作用:

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

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

回答by huangzonghao

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 tis the one I am currently using.

我认为对于您的特殊目的,推特可能是更好的选择。Twitter 接受来自 API 的推文。因此,您需要做的是设置一个帐户,以定期或以事件触发的方式发布您的系统状态,并在您自己的个人帐户中关注它。并且已经有很多开源项目专注于通过 API 发推文,而t是我目前正在使用的项目。

回答by Att Righ

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.

有一个 libpurple 扩展(https://github.com/dequis/purple-facebook)可以工作。然而紫色似乎不支持消息历史的想法。这是一种耻辱,因为我认为离线消息是大多数人使用 facebook 的默认方式。

There is an single use command tool for facebook as well: https://www.npmjs.com/package/fb-messenger-cliwhich 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.

还有一个用于 facebook 的一次性命令工具:https: //www.npmjs.com/package/fb-messenger-cli,它确实支持历史记录。不幸的是,这是一个 TUI 而不是命令行应用程序,并且似乎不依赖于单独的 facebook 库。一些黑客或可怕的期望胶可以解决这个问题。

回答by xurei

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

我刚刚针对该用例发布了一项服务:https: //www.nimrod-messenger.io/

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

它处于早期阶段。非常欢迎反馈:-)

回答by Vasily Bodnarchuk

Sending facebook message in bash script

在 bash 脚本中发送 Facebook 消息

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.

我需要一个检查服务器的脚本(适用于我的工作/本地 mac)。如果有问题,脚本会在 Facebook 上向我发送消息。

Dependencies

依赖关系

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

需要安装:https : //github.com/mjkaufer/Messer

Solution, bash script

解决方案,bash脚本

FB_SENDER_LOGIN=""
FB_SENDER_PASSWORD=""

function send_fb_message {
    FB_MESSER_COMAND="messer $FB_SENDER_LOGIN $FB_SENDER_PASSWORD --command='m \"\" '"
    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"

回答by Vasily Bodnarchuk

Automated Facebook message

自动 Facebook 消息

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)

看看这个名为 Messer 的 repo https://github.com/mjkaufer/Messer
(它也适用于 2FA,但不适用于应用程序密码)

Implementation

执行

  1. See Readme

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

  1. 请参阅自述文件

  2. 我需要它自动运行,所以我使用它的非交互模式和 bash 脚本:

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/messerexecutable 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.
  • 我不喜欢通过 NPM 全局安装这样的东西,所以我使用/node_modules/.bin/messer了项目文件夹中的可执行文件。
  • 使用双引号转义而不是单引号,以便能够在命令中使用变量。
  • 缺点:Messer 只能发送,不能接收。