Skip to content

Commit

Permalink
Merge pull request #1
Browse files Browse the repository at this point in the history
* Add node-notifier to show notifications whenever new message arrive

* Add load: groupname/username command, refactor code to match ES6 standard and edit README.md to reflect latest changes

* Fix typo in notifications

(From ameerthehacker)
  • Loading branch information
ameerthehacker authored and AstroCB committed Oct 13, 2017
1 parent 66be3f8 commit 95d8500
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 209 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Messenger-CLI

Messenger-CLI (MCLI) provides a way to access Facebook Messenger from the command line. You can send and receive messages in both group chats and direct messages.
Messenger-CLI (MCLI) provides a way to access Facebook Messenger from the command line. You can send and receive messages with notifications in both group chats and direct messages.

It was written using [Node.js](https://nodejs.org) and [Facebook Chat API](https://github.com/Schmavery/facebook-chat-api).

Expand All @@ -22,6 +22,13 @@ MCLI will search your 20 most recent threads (configurable) for a chat name (for

To send a message to someone else, simply specify a new recipient using the same syntax shown above.

```
> load: groupname/username
```

MCLI will search your 20 most recent threads (configurable) for a chat name (for group chats) or a person's name (for one-on-one chats) that matches `groupname/username`. Then it will load the latest 10 messages, you can simply continue to type new messages and they will be sent to that specified groupname or username.


## Special commands
Below are a list of commands that, when included in messages, will not appear in the final text sent to the recipient, but will influence the behavior of the chat in some way.

Expand Down
63 changes: 48 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const login = require("facebook-chat-api");
const fs = require("fs");
const readline = require("readline");
const notifier = require('node-notifier');
// Internal colors module for Terminal output'
const colored = require("./colors").colorString;
// Global access variables
Expand Down Expand Up @@ -90,6 +91,11 @@ function main(api) {

// Log the incoming message and reset the prompt
newPrompt(`${colored(uinfo[msg.senderID].firstName, "fgblue")} in ${colored(tinfo.name, "fggreen")} ${atext}`, rl);
// Show up the notification for the new incoming message
notifier.notify({
title: 'Messenger CLI',
message: `You have unread messages from: ${uinfo[msg.senderID].firstName}`
});
});
});
} else if (msg.type == "event") { // Chat event received
Expand All @@ -113,21 +119,48 @@ function main(api) {
}
} else {
// Search for the group specified in the message
const search = line.substring(0, terminator);
getGroup(search, (err, group) => {
if (!err) {
// Send message to matched group
sendReplacedMessage(line.substring(terminator + 1), group, rl);

// Store the information of the last recipient so you don't have to specify it again
active = group;

// Update the prompt to indicate where messages are being sent by default
rl.setPrompt(colored(`[${active.name}] `, "fggreen"));
} else {
logError(err);
}
});
const cmd = line.substring(0, terminator);
if(cmd == "load") {
const search = line.substring(terminator + 1);
getGroup(search, (err, group) => {
if (!err) {
// Store the information of the last recipient so you don't have to specify it again
active = group;
// Load older 10 messages
api.getThreadHistory(group.threadID, 10, undefined, (err, history) => {
if(!err) {
for(let i = 0; i < history.length; i++) {
console.log(`${colored(history[i].senderName, "fggreen")}: ${history[i].body}`);
}
rl.setPrompt(colored(`[${active.name}] `, "fggreen"));
timestamp = history[0].timestamp;
}
else {
logError(err);
}
});
// Update the prompt to indicate where messages are being sent by default
} else {
logError(err);
}
});
}
else {
getGroup(cmd, (err, group) => {
if (!err) {
// Send message to matched group
sendReplacedMessage(line.substring(terminator + 1), group, rl);

// Store the information of the last recipient so you don't have to specify it again
active = group;

// Update the prompt to indicate where messages are being sent by default
rl.setPrompt(colored(`[${active.name}] `, "fggreen"));
} else {
logError(err);
}
});
}
}
});
}
Expand Down
Loading

0 comments on commit 95d8500

Please sign in to comment.