npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

iconic-narada

v1.0.1

Published

Iconic Narada, developer friendly boilerplate to help you connect Social Media/Messaging platforms via Webhooks.

Downloads

5

Readme

Iconic Narada | Social Media/Messaging Webhooks Boilerplate

npm version node version build status License join slack channel

Iconic Narada, developer friendly boilerplate to help you connect Social Media/Messaging platforms via Webhooks.

Supported Platforms:

  • Facebook
  • Facebook Messenger
  • Twitter
  • Twitter Direct

Why Iconic-Narada?:

  • Developer friendly
  • Raw social media request/response objects
  • Code from the future (ECMAScript 6 compatible)
  • Database of your choice
  • Server of your choice (Not specific to AWS lambda)
  • Not only for messaging platforms, supports social media too
  • Multiple platforms/channels in 1 boilerplate
  • Better error handling
  • Very low learning curve

overall-structure

Installation

Choose one of the following options:

  • Install with npm: npm install iconic-narada
  • To install Iconic Narada from source, first clone the repository and then run: npm install.

Edit config

In app root directory, rename .sample-env to .env. You can set app wide environment constants here and access them in your code with dotenv module and process.env.

In each example bot directory, you will find config.json. You can set bot specific constants here and access them by importing this file into your bot code. You may also instead retrieve this information from database for additional security.

Enable/Disable a Platform

Each platform has it's own router, controller, parser, elements and connector. The main router in routes.js hands over new received event to the router of specific platform.

data-and-logic-flow

To enable a new platform, import the platform from platforms folder and create a new route for that platform in the main router(routes.js). E.g.: The below code will create a route like - https://your.domain/webhook/facebook

import facebookRouter from './platforms/facebook/router';

app.use('/facebook', facebookRouter);

Run

To start the app without babel, run node app.js.

To start the app with babel, run node start.js

Basic Usage

The business logic of bot is handled in bots. Each platform can have it's own configuration which may also be retrieved from database or environment file.

Once a platform is enabled by adding it to routes, the platform specific Controller in platforms/<platform>/controller.js parses every new event and hands over the parsed event to bots/<platform>/index.js. You can either process the parsed event here or create multiple bots for that platform and redirect the parsed event to respective bot.

Bots can use Elements from platforms/<platform>/elements.js to create JSON objects to form a reply or action and, use Connector from platforms/<platform>/connector.js to send the reply or action to platform APIs.

Here are some examples of typical usage:

Facebook Elements and Connector

Importing elements and connector

import FacebookConnector from '../../../platforms/facebook/connector';
import * as FacebookElements from '../../../platforms/facebook/elements';

Creating a message

Create a plain text message.

const message = new FacebookElements.Text(`Hello there!`);

For more detailed samples of Facebook Elements, check out this doc.

Sending a message

Set the Recipient ID.

Event object contains basic information like senderId, recipientId, etc based on the type of event received.

const recipientId = event.senderId;

Set a message.

const message = new FacebookElements.Text(`Hello there!`);

Set the array of replies to be sent.

Reply element method requires a recipient ID and a message. It also accepts a string in place of message object.

const replies = [
    new FacebookElements.Reply(recipientId, message),
    new FacebookElements.Reply(recipientId, 'What\'s up?'),
];

Send each reply in sequence.

const facebookConnector = new FacebookConnectorACCESS_TOKEN);

for (const reply of replies) {
    await facebookConnector.sendMessage(botConfig.PAGE_ID, reply)
        .catch(err => logger.error(err));
}

Sending an action.

You can also send an action with/without/before/after a Reply element.

const replies = [
    new FacebookElements.MarkSeen(recipientId),
    new FacebookElements.TypingOn(recipientId),
    new FacebookElements.TypingOff(recipientId),
];

Getting user profile.

You can get user profile with getUserProfile method.

const facebookConnector = new FacebookConnectorACCESS_TOKEN);

const userProfile = await facebookConnector.getUserProfile(recipientId)
    .catch(err => logger.debug(err));

Twitter Elements and Connector

Importing elements and connector

import TwitterConnector from '../../../platforms/twitter/connector';
import * as TwitterElements from '../../../platforms/twitter/elements';

Creating a message

Create a plain text message.

const message = new TwitterElements.Text(`Hi there!`);

For more detailed samples of Twitter Elements, check out this doc.

Sending a message.

Set the Recipient ID.

Event object contains basic information like senderId, recipientId, etc based on the type of event received.

const recipientId = event.senderId;

Set a message.

const message = new TwitterElements.Text(`Hello there!`);

Create an array of replies to be sent.

Reply element method requires a recipient ID and a message. It also accepts a string in place of message object.

const replies = [
    new TwitterElements.Reply(recipientId, message),
    new TwitterElements.Reply(recipientId, 'What\'s up?'),
];

Send each reply in sequence.

const twitterConnector = new TwitterConnectorOAUTH);

for (const reply of replies) {
    await twitterConnector.sendMessage(reply)
      .catch(err => logger.error(err));
}

Contributing

Contributions are generally appreciated. But we are exclusively looking for contributers to help us extend our support to Slack, Telegram, Instagram, WhatsApp, Skype, Youtube, Viber, Amazon Alexa, Line, Kik & make it a all-in-one open source webhooks boilerplate.

See the Contributors' guide for more information.

Authors

License

The source code of Iconic Narada boilerplate is licensed under MIT.