All Projects → kahwee → ranka

kahwee / ranka

Licence: Apache-2.0 license
Facebook Messaging bot with greater expressivity

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to ranka

Mtproto Core
Telegram API JS (MTProto) client library for browser and nodejs
Stars: ✭ 242 (+952.17%)
Mutual labels:  messenger
Vesta
Vesta is a simple decentralized p2p chat group using ruby.
Stars: ✭ 44 (+91.3%)
Mutual labels:  messenger
comm
A hypothetical, distributed, encrypted, instant messaging protocol.
Stars: ✭ 63 (+173.91%)
Mutual labels:  messenger
Tdesktop
Telegram Desktop messaging app
Stars: ✭ 17,508 (+76021.74%)
Mutual labels:  messenger
golem
Open-source chatbot framework for python developers. Batteries included 🔋🔋
Stars: ✭ 38 (+65.22%)
Mutual labels:  messenger
dialogflow-watchnow-messenger
WatchNow FB Messenger bot with DialogFlow & Golang 💬
Stars: ✭ 24 (+4.35%)
Mutual labels:  messenger
Pybitmessage
Reference client for Bitmessage: a P2P encrypted decentralised communication protocol:
Stars: ✭ 2,661 (+11469.57%)
Mutual labels:  messenger
messenger
Chat/Message system for Laravel.
Stars: ✭ 69 (+200%)
Mutual labels:  messenger
qd-messages-ts
No ads, no tracking. Just a lightning fast peer-to-peer cross-platform messenger that doesn’t sell you out.
Stars: ✭ 22 (-4.35%)
Mutual labels:  messenger
LaravelMessenger
💬 Simple messaging system for Laravel
Stars: ✭ 83 (+260.87%)
Mutual labels:  messenger
molch
An implementation of the axolotl ratchet based on libsodium.
Stars: ✭ 24 (+4.35%)
Mutual labels:  messenger
vue-socials
💬 Social media share buttons and counts for Vue.js
Stars: ✭ 32 (+39.13%)
Mutual labels:  messenger
iGap-iOS
iGap Client for iOS Source Code
Stars: ✭ 18 (-21.74%)
Mutual labels:  messenger
Swiftybot
How to create a Telegram, Facebook Messenger, and Google Assistant bot with Swift using Vapor on Ubuntu / macOS.
Stars: ✭ 247 (+973.91%)
Mutual labels:  messenger
background-service-lib
Essential classes for reliable background services.
Stars: ✭ 24 (+4.35%)
Mutual labels:  messenger
Botmaster
The chatbot framework for your serious projects
Stars: ✭ 239 (+939.13%)
Mutual labels:  messenger
telectron
Telegram desktop client [WIP]
Stars: ✭ 19 (-17.39%)
Mutual labels:  messenger
go-peer
Library for create secure and anonymity decentralized networks.
Stars: ✭ 74 (+221.74%)
Mutual labels:  messenger
LAN-Messenger
Official open-source repository for LAN Messenger
Stars: ✭ 17 (-26.09%)
Mutual labels:  messenger
bkit
build a messenger bot using HTML
Stars: ✭ 36 (+56.52%)
Mutual labels:  messenger

ranka

Facebook Messaging bot with greater expressivity to be used in conjunction with Express.

Demo

Setting up

First, you will need to instantiate Ranka together with Express

const express = require('express')
const app = express()
const Ranka = require('ranka')
const ranka = new Ranka({
  serverURL: '',
  validationToken: '',
  pageAccessToken: ''
})

Then, use your webhook this way:

app.use('/webhook', Ranka.router({
  ranka: ranka
}))

ranka.on('message', (req, res) => {
  res
    .sendText('mm...')
    .typing()
    .wait(3000)
    .sendText(`Did you say "${req.body.message.text}"?`)
    .sendImage('http://i.giphy.com/FdQj4yMGloVMI.gif')
    .exec()
})

Bind your Express server port if you haven't already.

app.listen(3000, function () {
  console.log('Example app listening on port 3000!')
})

Request Object

Request Properties

Every Facebook callback is supported. This includes:

  • sender
  • recipient
  • timestamp
  • message

For example, when Facebook sends back the following:

{
  "sender":{
    "id":"USER_ID"
  },
  "recipient":{
    "id":"PAGE_ID"
  },
  "timestamp":1458692752478,
  "message":{
    "mid":"mid.1457764197618:41d102a3e1ae206a38",
    "seq":73,
    "text":"hello, world!",
    "quick_reply": {
      "payload": "DEVELOPER_DEFINED_PAYLOAD"
    }
  }
}

console.log(req.message) returns you with:

{
  "mid":"mid.1457764197618:41d102a3e1ae206a38",
  "seq":73,
  "text":"hello, world!",
  "quick_reply": {
    "payload": "DEVELOPER_DEFINED_PAYLOAD"
  }
}

Request Methods

isThumbsUp()

Returns true if it is Facebook thumbs up.

req.isThumbsUp()

hasAttachments()

Returns True, if there are attachments

getAttachmentsByType(type)

Returns an array of all attachments with specified type.

If no attachments of type is found, return an empty array.

req.getAttachmentsByType('location')

Response Object

Response chainable methods

The methods are chainable, you can use multiple methods and run .exec() at the end.

senderAction(value)

Set typing indicators or send read receipts using the Send API, to let users know you are processing their request.

res
  .senderAction('mark_seen')
  .exec()

typing(isTyping)

isTyping is defaulted to true.

Example:

res
  .typing()
  .wait(1000)
  .sendText('Done!')
  .exec()

send(message)

This is equivalent to sending this payload to Facebook Messenger API where message is the passed in as an object.

{
  "recipient": {
    "id": "AUTO_FILLED_USER_ID"
  },
  "message": message
}

In this case, we can send a basic text:

res
  .send({ text: 'Hello there!' })
  .exec()

Correspondingly, ranka generates the data to send back to Facebook:

{
  "recipient": {
    "id": "AUTO_FILLED_USER_ID"
  },
  "message": { 
    "text": "Hello there!" 
  }
}

The remaining commands are convenient helpers that wraps the send() method.

sendText(text)

Sends a text as a reply to the sender.

res
  .sendText('Hello!')
  .exec()

sendQuickReplies(text, quick_replies)

You can send some quick replies:

res
  .sendQuickReplies('Please share your location:', [
    {
      content_type: 'location'
    }
  ])
  .exec()

sendAudio(url)

You can share a sound URL using the Send API.

See more in Facebook Messenger documentation.

sendVideo(url)

You can share a video URL using the Send API.

See more in Facebook Messenger documentation.

sendTemplate(payload)

You can send a message template and provide a payload object:

req
  .sendTemplate({
    "template_type":"button",
    "text":"What do you want to do next?",
    "buttons":[
      {
        "type":"web_url",
        "url":"https://petersapparel.parseapp.com",
        "title":"Show Website"
      },
      {
        "type":"postback",
        "title":"Start Chatting",
        "payload":"USER_DEFINED_PAYLOAD"
      }
    ]
  })
  .exec()

Using the above, you can send Button Template, Generic Template, List Template, Reciept Template, Airline Boarding Pass Template and more.

License

Apache 2.0 License

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].