New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

messaging-api-messenger

Package Overview
Dependencies
Maintainers
2
Versions
112
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

messaging-api-messenger

Messaging API client for Messenger

  • 0.2.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.2K
increased by21.08%
Maintainers
2
Weekly downloads
 
Created
Source

messaging-api-messenger

Messaging API client for Messenger

Table of Contents

Installation

npm i --save messaging-api-messenger

or

yarn add messaging-api-messenger

Usage

Initialize

import { MessengerClient } from 'messaging-api-line';

// get accessToken from facebook developers website
const client = MessengerClient.connect(accessToken);

Call API

async function() {
  await client.sendText(recipientId, text, options);
}

or

client.sendText(recipientId, text, options).then(() => {
  // do something
});

API Reference

All methods return a Promise.

User

getUserProfile(userId)
client.getUserProfile('1')
  .then(user => {
    console.log(user);
    // {
    //   first_name: 'Johnathan',
    //   last_name: 'Jackson',
    //   profile_pic: 'https://example.com/pic.png',
    //   locale: 'en_US',
    //   timezone: 8,
    //   gender: 'male',
    // }
  });

Send API

Official docs
Content types

sendRawBody(body)
client.sendRawBody({
  recipient: {
    id: '1',
  },
  message: {
    text: 'Hello!',
  },
});
send(userId)
client.send('1', {
  text: 'Hello!',
});
sendText(userId, text [, options])
client.sendText('1', 'Hello!');
sendIssueResolutionText(userId, text)
client.sendIssueResolutionText('1', 'Hello!');
sendAttachment(userId, attachment)
client.sendAttachment('1', {
  type: 'image',
  payload: {
    url: 'https://example.com/pic.png',
  },
});
sendAudio(userId, url)
client.sendAudio('1', 'https://example.com/audio.mp3');
sendImage(userId, url)
client.sendImage('1', 'https://example.com/pic.png');
sendVideo(userId, url)
client.sendVideo('1', 'https://example.com/video.mp4');
sendFile(userId, url)
client.sendFile('1', 'https://example.com/word.docx');
sendTemplate(userId, template)
client.sendTemplate('1', {
  template_type: 'button',
  text: 'title',
  buttons: [
    {
      type: 'postback',
      title: 'Start Chatting',
      payload: 'USER_DEFINED_PAYLOAD',
    },
  ],
});

Official docs

sendButtonTemplate(userId, title, buttons)
client.sendButtonTemplate('1', 'my_title', [
  {
    type: 'postback',
    title: 'Start Chatting',
    payload: 'USER_DEFINED_PAYLOAD',
  },
]

Official docs

sendGenericTemplate(userId, elements)
client.sendGenericTemplate('1', [
  {
    title: "Welcome to Peter's Hats",
    image_url: 'https://petersfancybrownhats.com/company_image.png',
    subtitle: "We've got the right hat for everyone.",
    default_action: {
      type: 'web_url',
      url: 'https://peterssendreceiveapp.ngrok.io/view?item=103',
      messenger_extensions: true,
      webview_height_ratio: 'tall',
      fallback_url: 'https://peterssendreceiveapp.ngrok.io/',
    },
    buttons: [
      {
        type: 'postback',
        title: 'Start Chatting',
        payload: 'DEVELOPER_DEFINED_PAYLOAD',
      },
    ],
  },
]);

Official docs

sendShippingUpdateTemplate(userId, elements)
client.sendShippingUpdateTemplate('1', [
  {
    title: "Welcome to Peter's Hats",
    image_url: 'https://petersfancybrownhats.com/company_image.png',
    subtitle: "We've got the right hat for everyone.",
    default_action: {
      type: 'web_url',
      url: 'https://peterssendreceiveapp.ngrok.io/view?item=103',
      messenger_extensions: true,
      webview_height_ratio: 'tall',
      fallback_url: 'https://peterssendreceiveapp.ngrok.io/',
    },
    buttons: [
      {
        type: 'postback',
        title: 'Start Chatting',
        payload: 'DEVELOPER_DEFINED_PAYLOAD',
      },
    ],
  },
]);
sendReservationUpdateTemplate(userId, elements)
client.sendReservationUpdateTemplate('1', [
  {
    title: "Welcome to Peter's Hats",
    image_url: 'https://petersfancybrownhats.com/company_image.png',
    subtitle: "We've got the right hat for everyone.",
    default_action: {
      type: 'web_url',
      url: 'https://peterssendreceiveapp.ngrok.io/view?item=103',
      messenger_extensions: true,
      webview_height_ratio: 'tall',
      fallback_url: 'https://peterssendreceiveapp.ngrok.io/',
    },
    buttons: [
      {
        type: 'postback',
        title: 'Start Chatting',
        payload: 'DEVELOPER_DEFINED_PAYLOAD',
      },
    ],
  },
]);
sendIssueResolutionTemplate(userId, elements)
client.sendIssueResolutionTemplate('1', [
  {
    title: "Welcome to Peter's Hats",
    image_url: 'https://petersfancybrownhats.com/company_image.png',
    subtitle: "We've got the right hat for everyone.",
    default_action: {
      type: 'web_url',
      url: 'https://peterssendreceiveapp.ngrok.io/view?item=103',
      messenger_extensions: true,
      webview_height_ratio: 'tall',
      fallback_url: 'https://peterssendreceiveapp.ngrok.io/',
    },
    buttons: [
      {
        type: 'postback',
        title: 'Start Chatting',
        payload: 'DEVELOPER_DEFINED_PAYLOAD',
      },
    ],
  },
]);
sendListTemplate(userId, items, topElementStyle)
client.sendListTemplate('1', [
    {
      title: 'Classic T-Shirt Collection',
      image_url:
        'https://peterssendreceiveapp.ngrok.io/img/collection.png',
      subtitle: 'See all our colors',
      default_action: {
        type: 'web_url',
        url: 'https://peterssendreceiveapp.ngrok.io/shop_collection',
        messenger_extensions: true,
        webview_height_ratio: 'tall',
        fallback_url: 'https://peterssendreceiveapp.ngrok.io/',
      },
      buttons: [
        {
          title: 'View',
          type: 'web_url',
          url: 'https://peterssendreceiveapp.ngrok.io/collection',
          messenger_extensions: true,
          webview_height_ratio: 'tall',
          fallback_url: 'https://peterssendreceiveapp.ngrok.io/',
        },
      ],
    },
  ],
  [
    {
      type: 'postback',
      title: 'Start Chatting',
      payload: 'USER_DEFINED_PAYLOAD',
    },
  ],
  'compact'
);

Official docs

sendReceiptTemplate

Official docs

sendAirlineBoardingPassTemplate

Official docs

sendAirlineCheckinTemplate

Official docs

sendAirlineItineraryTemplate

Official docs

  • sendAirlineFlightUpdateTemplate

Official docs

sendQuickReplies(userId, message, items)
client.sendQuickReplies('1', { text: 'Pick a color:' }, [
    {
      content_type: 'text',
      title: 'Red',
      payload: 'DEVELOPER_DEFINED_PAYLOAD_FOR_PICKING_RED',
    },
  ]
);

Official docs

sendSenderAction
client.sendSenderAction('1', 'typing_on');

Official docs

turnTypingIndicatorsOn(userId)
client.turnTypingIndicatorsOn('1');
turnTypingIndicatorsOff(userId)
client.turnTypingIndicatorsOff('1');

Upload API

Official docs

uploadAttachment
uploadAudio
uploadImage
uploadVideo
uploadFile

Messenger Profile

Official docs

getMessengerProfile
setMessengerProfile
deleteMessengerProfile

Get Started Button

Official docs

getGetStartedButton
setGetStartedButton
deleteGetStartedButton

Persistent Menu

Official docs

getPersistentMenu
setPersistentMenu
deletePersistentMenu

Greeting Text

Officail docs

getGreetingText
setGreetingText
deleteGreetingText

Domain Whitelist

Official docs

getDomainWhitelist
setDomainWhitelist
deleteDomainWhitelist

Account Linking URL

Official docs

getAccountLinkingURL
setAccountLinkingURL
deleteAccountLinkingURL

Payment Settings

Official docs

getPaymentSettings
setPaymentPrivacyPolicyURL
setPaymentPublicKey
setPaymentTestUsers
deletePaymentSettings

Target Audience

Official docs

getTargetAudience
setTargetAudience
deleteTargetAudience

Keywords

FAQs

Package last updated on 11 Jul 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc