-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minor design improvements. Work in progress on bot replies.
- Loading branch information
Glitch (glitch-fediverse-bot)
committed
Oct 9, 2018
1 parent
e7d047b
commit 7a04d1a
Showing
27 changed files
with
680 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
sessions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Bot logic | ||
|
||
The files in the `/bot` folder contain the source code for the bot's behavior. | ||
|
||
- Inside `bot.js` you'll find internal methods, like `create_post` and `delete_post`. | ||
- To change bot's responses to messages it receives, see `responses.js`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
Here you can modify how the bot responds to messages it receives. | ||
*/ | ||
|
||
module.exports = function(data, callback_function) { | ||
/* | ||
At the end of this function we need to pass an error message and a response text. | ||
Let's set up some default values. | ||
*/ | ||
|
||
var error = null, | ||
response = 'Hello 👋'; | ||
|
||
/* | ||
The data object this function receives looks like this: | ||
data = { | ||
payload: 'The original data object.', | ||
message_body: 'The content of the message sent to the bot.', | ||
message_from: 'The URL of the message sender.' | ||
} | ||
message_body and message_from come from the payload object, so we can access them more conveniently. If we need more details, we can get those from the payload object itself. | ||
*/ | ||
|
||
console.log(`new message from ${data.message_from}:`) | ||
console.log(data.message_body); | ||
|
||
/* | ||
We can modify the response text. | ||
*/ | ||
|
||
if (data.message_body.toLowerCase().indexOf('hello') > -1){ | ||
response = 'Hi 👋'; | ||
} | ||
|
||
/* | ||
Finally, we pass the error and reply message to the callback function that sends it to the author of the message that the bot received and saves it to the post database. | ||
*/ | ||
|
||
callback_function(error, response); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
**Work in progress** | ||
|
||
 | ||
|
||
# Bot replies | ||
|
||
To use bot replies, update `bot/responses.js` with a function that returns a reply message. | ||
|
||
|
||
TODO: | ||
|
||
- correctly dedupe events | ||
- add support for private messages | ||
- send notification when posting reply | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
Here you can modify how the bot responds to messages it receives. | ||
*/ | ||
|
||
module.exports = function(data, callback_function) { | ||
/* | ||
At the end of this function we need to pass an error message and a response text. | ||
Let's set up some default values. | ||
*/ | ||
|
||
var error = null, | ||
response = 'Hello 👋'; | ||
|
||
/* | ||
The data object this function receives looks like this: | ||
data = { | ||
payload: 'The original data object.', | ||
message_body: 'The content of the message sent to the bot.', | ||
message_from: 'The URL of the message sender.' | ||
} | ||
message_body and message_from come from the payload object, so we can access them more conveniently. If we need more details, we can get those from the payload object itself. | ||
*/ | ||
|
||
console.log(`new message from ${data.message_from}:`) | ||
console.log(data.message_body); | ||
|
||
/* | ||
We can modify the response text. | ||
*/ | ||
|
||
if (data.message_body.toLowerCase().indexOf('hello') > -1){ | ||
response = 'Hi 👋'; | ||
} | ||
|
||
/* | ||
Finally, we pass the error and reply message to the callback function that sends it to the author of the message that the bot received and saves it to the post database. | ||
*/ | ||
|
||
callback_function(error, response); | ||
}; |
Oops, something went wrong.