SkillAgentSearch skills...

Botly

Simple Facebook Messenger Bot API

Install / Use

/learn @miki2826/Botly
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

<img src="https://raw.githubusercontent.com/miki2826/botly/master/botly_logo.png" width="250" height="250" />

Built with Grunt Build Status Test Coverage npm version Dependency Status devDependency Status npm downloads license NPM

Simple Facebook Messenger Platform Bot API

Install

npm i botly --save

Example

const express = require("express");
const bodyParser = require("body-parser");
const Botly = require("botly");
const botly = new Botly({
    accessToken: pageAccessToken, // page access token provided by facebook
    verifyToken: verificationToken, // needed when using express - the verification token you provided when defining the webhook in facebook
    webHookPath: yourWebHookPath, // defaults to "/",
    notificationType: Botly.CONST.REGULAR, // already the default (optional)
    FB_URL: 'https://graph.facebook.com/v2.6/' // this is the default - allows overriding for testing purposes
});

botly.on("message", (senderId, message, data) => {
    let text = `echo: ${data.text}`;

    botly.sendText({
      id: senderId,
      text: text
    });
});

const app = express();
app.use(bodyParser.json({
    verify: botly.getVerifySignature(process.env.APP_SECRET) //allow signature verification based on the app secret
}));
app.use(bodyParser.urlencoded({ extended: false }));
app.use("/webhook", botly.router());
app.listen(3000);

You can also clone the repository and run a complete bot example from the example folder.

API

send (options[, callback])

botly.send({
    id: userId,
    message: {text: "Hi There!"}
}, function (err, data) {
        //log it
});

upload (options[, callback])

botly.upload({
    type: Botly.CONST.ATTACHMENT_TYPE.IMAGE,
    payload: {url: "http://example.com/image.png"}
}, (err, data) => {
    //save data.attachment_id
});

sendText (options[, callback])

botly.sendText({id: userId, text: "Hi There!"}, function (err, data) {
        //log it
});

sendAttachment (options[, callback])

Also supports options.filedata = '@/tmp/receipt.pdf'.

botly.sendAttachment({
    id: userId,
    type: Botly.CONST.ATTACHMENT_TYPE.IMAGE,
    payload: {url: "http://example.com/image.png"}
}, (err, data) => {
        //log it
});

sendImage (options[, callback])

botly.sendImage({id: userId, url: "http://example.com/image.png"}, (err, data) => {
        //log it
});

sendButtons (options[, callback])

let buttons = [];
buttons.push(botly.createWebURLButton("Go to Askrround", "http://askrround.com"));
buttons.push(botly.createPostbackButton("Continue", "continue"));
botly.sendButtons({id: userId, text: "What do you want to do next?", buttons: buttons}
    , (err, data) => {
        //log it
});

sendGeneric (options[, callback])

let buttons = [];
buttons.push(botly.createWebURLButton("Go to Askrround", "http://askrround.com"));
buttons.push(botly.createPostbackButton("Continue", "continue"));
let element = {
  title: "What do you want to do next?",
  item_url: "http://example.com",
  image_url: "http://example.com/image.png",
  subtitle: "Choose now!",
  buttons: buttons
}
botly.sendGeneric({id: userId, elements: element, aspectRatio: Botly.CONST.IMAGE_ASPECT_RATIO.HORIZONTAL}, (err, data) => {
    console.log("send generic cb:", err, data);
});

sendList (options[, callback])


const element = botly.createListElement({
    title: 'First Element',
    image_url: 'https://peterssendreceiveapp.ngrok.io/img/collection.png',
    subtitle: 'subtitle text',
    buttons: [
        {title: 'Payload Button', payload: 'first_element'},
    ],
    default_action: {
        'url': 'https://peterssendreceiveapp.ngrok.io/shop_collection',
    }
});
const element2 = botly.createListElement({
    title: 'Other Element',
    image_url: 'https://peterssendreceiveapp.ngrok.io/img/collection.png',
    subtitle: 'even more subtitle',
    buttons: [
        {title: "Go to Askrround", url: "http://askrround.com"},
    ],
    default_action: {
        'url': 'https://peterssendreceiveapp.ngrok.io/shop_collection',
    }
});
botly.sendList({id: sender, elements: [element, element2], buttons: botly.createPostbackButton('More Plans', 'MORE_PLANS'), top_element_style: Botly.CONST.TOP_ELEMENT_STYLE.LARGE},function (err, data) {
      console.log('send list cb:', err, data);
});

sendAction (options[, callback])

botly.sendAction({id: userId, action: Botly.CONST.ACTION_TYPES.TYPING_ON}, (err, data) => {
        //log it
});

sendReceipt (options[, callback])

let payload = {
    "recipient_name": "Stephane Crozatier",
    "order_number": "12345678902",
    "currency": "USD",
    "payment_method": "Visa 2345",
    "order_url": "http://petersapparel.parseapp.com/order?order_id=123456",
    "timestamp": "1428444852",
    "elements": [
        {
            "title": "Classic White T-Shirt",
            "subtitle": "100% Soft and Luxurious Cotton",
            "quantity": 2,
            "price": 50,
            "currency": "USD",
            "image_url": "http://petersapparel.parseapp.com/img/whiteshirt.png"
        },
        {
            "title": "Classic Gray T-Shirt",
            "subtitle": "100% Soft and Luxurious Cotton",
            "quantity": 1,
            "price": 25,
            "currency": "USD",
            "image_url": "http://petersapparel.parseapp.com/img/grayshirt.png"
        }
    ],
    "address": {
        "street_1": "1 Hacker Way",
        "street_2": "",
        "city": "Menlo Park",
        "postal_code": "94025",
        "state": "CA",
        "country": "US"
    },
    "summary": {
        "subtotal": 75.00,
        "shipping_cost": 4.95,
        "total_tax": 6.19,
        "total_cost": 56.14
    },
    "adjustments": [
        {
            "name": "New Customer Discount",
            "amount": 20
        },
        {
            "name": "$10 Off Coupon",
            "amount": 10
        }
    ]
};
botly.sendReceipt({id: sender, payload: payload}, function (err, data) {
    console.log("send generic cb:", err, data);
});

setGetStarted (options[, callback])

botly.setGetStarted({pageId: "myPage", payload: "GET_STARTED_CLICKED"}, (err, body) => {
    //log it
});

setGreetingText (options[, callback])

botly.setGreetingText({
    pageId: "myPage",
     greeting: [{
           "locale":"default",
           "text":"Hello!"
       }, 
View on GitHub
GitHub Stars92
CategoryDevelopment
Updated1y ago
Forks32

Languages

JavaScript

Security Score

80/100

Audited on May 19, 2024

No findings