Skip to content
This repository has been archived by the owner on Jan 21, 2021. It is now read-only.

Commit

Permalink
Added tools class to comment object
Browse files Browse the repository at this point in the history
  • Loading branch information
maxtomczyk committed Dec 11, 2018
1 parent 910b1e6 commit a50784b
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 57 deletions.
136 changes: 79 additions & 57 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -2,63 +2,65 @@

**IMPORTANT!** Incredbot is still under development, but it was successfully used for some projects!

* [What is incredbot?](#what-is-incredbot-)
* [Including](#including)
- [Configuration options](#configuration-options)
* [Server](#server)
+ [Starting server](#starting-server)
+ [Catching events](#catching-events)
+ [Server events](#server-events)
+ [Incredbot Message vs Raw Message](#incredbot-message-vs-raw-message)
* [Sender](#sender)
+ [Methods](#methods)
- [`text(message, options)`](#-text-message--options--)
- [`quick_replies(message, replies, options)`](#-quick-replies-message--replies--options--)
- [`buttons(text, buttons, options)`](#-buttons-text--buttons--options--)
- [`attachment(type, url, options)`](#-attachment-type--url--options--)
- [`generic(elements, options)`](#-generic-elements--options--)
* [Helpers](#helpers)
+ [Button](#button)
+ [Generic Message](#generic-message)
+ [Get Started Button](#get-started-button)
+ [Greeting](#greeting)
+ [Quick Reply](#quick-reply)
* [User object](#user-object)
+ [Get user data](#get-user-data)
+ [Send message](#send-message)
* [Static elements](#static-elements)
+ [`incredbot.send.setting(data)`](#-incredbotsendsetting-data--)
- [Greeting](#greeting-1)
- [Get Started Button](#get-started-button-1)
- [Persistent Menu](#persistent-menu)
* [Natural typing](#natural-typing)
* [Generator Module](#generator-module)
+ [Supported types](#supported-types)
- [Text](#text)
- [Quick Replies](#quick-replies)
- [Buttons](#buttons)
- [Generic](#generic)
+ [Frame class](#frame-class)
* [Broadcast API](#broadcast-api)
+ [Create Creative Message](#create-creative-message)
+ [Create label](#create-label)
+ [List labels](#list-labels)
+ [Delete label](#delete-label)
+ [Assign label to user](#assign-label-to-user)
+ [Remove label from user](#remove-label-from-user)
+ [List labels assigned to users](#list-labels-assigned-to-users)
+ [List broadcasts](#list-broadcasts)
+ [Get broadcast info](#get-broadcast-info)
+ [Cancel planned broadcast](#cancel-planned-broadcast)
+ [Send broadcast](#send-broadcast)
- [Options](#options)
+ [Start broadcast size estimationId](#start-broadcast-size-estimationid)
+ [Get estimation results](#get-estimation-results)
+ [Get metrics of broadcast](#get-metrics-of-broadcast)
* [Examples](#examples)
+ [Echo bot full example](#echo-bot-full-example)
* [License](#license)
* [About me 👨🏻‍💻](#about-me--------)
- [What is incredbot?](#what-is-incredbot-)
- [Including](#including)
- [Configuration options](#configuration-options)
- [Server](#server)
- [Starting server](#starting-server)
- [Catching events](#catching-events)
- [Server events](#server-events)
- [Incredbot Message vs Raw Message](#incredbot-message-vs-raw-message)
- [Sender](#sender)
- [Methods](#methods)
- [`text(message, options)`](#-text-message--options--)
- [`quick_replies(message, replies, options)`](#-quick-replies-message--replies--options--)
- [`buttons(text, buttons, options)`](#-buttons-text--buttons--options--)
- [`attachment(type, url, options)`](#-attachment-type--url--options--)
- [`generic(elements, options)`](#-generic-elements--options--)
- [Helpers](#helpers)
- [Button](#button)
- [Generic Message](#generic-message)
- [Get Started Button](#get-started-button)
- [Greeting](#greeting)
- [Quick Reply](#quick-reply)
- [User object](#user-object)
- [Get user data](#get-user-data)
- [Send message](#send-message)
- [Static elements](#static-elements)
- [`incredbot.send.setting(data)`](#-incredbotsendsetting-data--)
- [Greeting](#greeting-1)
- [Get Started Button](#get-started-button-1)
- [Persistent Menu](#persistent-menu)
- [Natural typing](#natural-typing)
- [Generator Module](#generator-module)
- [Supported types](#supported-types)
- [Text](#text)
- [Quick Replies](#quick-replies)
- [Buttons](#buttons)
- [Generic](#generic)
- [Frame class](#frame-class)
- [Broadcast API](#broadcast-api)
- [Create Creative Message](#create-creative-message)
- [Create label](#create-label)
- [List labels](#list-labels)
- [Delete label](#delete-label)
- [Assign label to user](#assign-label-to-user)
- [Remove label from user](#remove-label-from-user)
- [List labels assigned to users](#list-labels-assigned-to-users)
- [List broadcasts](#list-broadcasts)
- [Get broadcast info](#get-broadcast-info)
- [Cancel planned broadcast](#cancel-planned-broadcast)
- [Send broadcast](#send-broadcast)
- [Options](#options)
- [Start broadcast size estimationId](#start-broadcast-size-estimationid)
- [Get estimation results](#get-estimation-results)
- [Get metrics of broadcast](#get-metrics-of-broadcast)
- [Comments interaction](#comments-interaction)
- [Private Reply](#private-reply)
- [Examples](#examples)
- [Echo bot full example](#echo-bot-full-example)
- [License](#license)
- [About me 👨🏻‍💻](#about-me--------)

## What is incredbot?

Expand Down Expand Up @@ -596,6 +598,26 @@ Fetches metrics of broadcast.
const metrics = await incredbot.broadcast.getMetrics('2209764209284356')
```

## Comments interaction

For now, the only interaction with comment which is supported by incredbot is private replying.

### Private Reply

`comment.tools.replyPrivately(text)`

Object tools, which contains replyPrivately method is only inside comment object. To send privte reply to comment you need to catch it's event first.

```javascript
bot.on('comment', async (comment, raw) => {
try {
await comment.tools.replyPrivately('Hi! This is private reply!')
} catch (e) {
console.error(e)
}
})
```

## Examples

### Echo bot full example
Expand Down
26 changes: 26 additions & 0 deletions models/CommentTools.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const axios = require('axios')

const logger = require('../modules/winston')

class CommentTools {
constructor(config, comment, user) {
this.comment = comment || null
this.user = user || null
this.private_reply_url = `https://graph.facebook.com/${config.api_version}/${this.comment.id}/private_replies?access_token=${config.access_token}`
}

async replyPrivately(text) {
try {
if (!text) throw new Error('Private reply must contain text message!')
const data = await axios.post(this.private_reply_url, {
message: text
})
return data.data
} catch (e) {
logger.error(e)
throw e
}
}
}

module.exports = CommentTools
3 changes: 3 additions & 0 deletions models/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const emitter = new Emitter()
const logger = require('../modules/winston')

const Sender = require('./Sender.js')
const CommentTools = require('./CommentTools.js')

const app = express()
app.use(bodyParser.urlencoded({
extended: false
Expand Down Expand Up @@ -106,6 +108,7 @@ class Server {
text: change.value.message,
id: change.value.comment_id
}
o.tools = new CommentTools(that.config, o.comment, o.user)
emitter.emit('comment', o, change)
}
})
Expand Down

0 comments on commit a50784b

Please sign in to comment.