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

botmaster-twitter-dm

v1.1.0

Published

The Twitter (Direct Messaging) Botmaster integration

Downloads

5

Readme

Botmaster-twitter-dm

Build Status Coverage Status npm-version license

This is the Twitter Direct Messaging integration for botmaster. It allows you to use your botmaster bot on Twitter using Direct messages.

Botmaster is a lightweight chatbot framework. Its purpose is to integrate your existing chatbot into a variety of messaging channels.

Documentation

Find the whole documentation for the framework on: http://botmasterai.com/

Installing

yarn add botmaster-twitter-dm

or

npm install --save botmaster-twitter-dm

Getting your Credentials

Twitter's setup is slightly more tricky than one would wish. Because Twitter requires you to create an actual account and not a page or a bot, you'll have to do a few more steps.

Setting up the bot account

  • Just create a standard twitter account as you would any other. Name it as you want.
  • navigate to your security and privacy settings (click on your image profile > settings > privacy and security settings)
  • scroll to the bottom of the page and make sure "Receive Direct Messages from anyone" is ticked. (currently this has to be done because of Twitter's rules concerning DMs, where in order to send a DM to someone, they have to be following you).

Setting up the app

  • Navigate to the somewhat hard to find Twitter developer app dashboard at: https://apps.twitter.com/
  • Click Create New App. Enter your details (callback URL is not required if you are starting from scratch here). 'Website' can take in a placeholder like (http://www.example.com)
  • Now navigate straight to the 'Permissions' tab(do this before going to the 'Keys and Access Tokens' tab). Select 'Read, Write and Access direct messages' and then click 'Update Setting'
  • Navigate to the 'Keys and Access Tokens' tab. You'll find your consumerKey and consumerSecret right here
  • Scroll down and click on 'Create my access token'. You now have your accessToken and your accessTokenSecret

! Makes sure not to create your access token before having reset your permissions. If you do that, you will need to change your permissions then regenerate your access token.

That should about do it. Because twitter DM is not completely separate from the rest of Twitter, it behaves quite differently from the other platforms on many aspects. These points are covered in working with botmaster.

Code

const Botmaster = require('botmaster');
const TwitterBot = require('botmaster-twitter-dm');
const botmaster = new Botmaster();

const twitterSettings = {
  credentials: {
    consumerKey: 'YOUR consumerKey',
    consumerSecret: 'YOUR consumerSecret',
    accessToken: 'YOUR accessToken',
    accessTokenSecret: 'YOUR accessTokenSecret',
  }
}

const twitterBot = new TwitterBot(twitterSettings);
botmaster.addBot(twitterBot);

botmaster.use({
  type: 'incoming',
  name: 'my-middleware',
  controller: (bot, update) => {
    return bot.reply(update, 'Hello world!');
  }
});

Note on attachment types and conversions

Attachment type conversion on incoming updates works as such for Twitter:

| Twitter Type | Botmaster conversion |--- |--- | photo | image | video | video | gif | video

!!!Yes gif becomes a video. because Twitter doesn't actually use gifs the way you would expect it to. It simply loops over a short .mp4 video.

Also, here's an important caveat for Twitter bot developers who are receiving attachments. Image links that come in from the Twitter API will be private and not public, which makes using them quite tricky. You might need to make authenticated requests to do so. The twitterBot objects you will receive in the update will have a bot.twit object. Documentation for how to use this is available here.

Receiving and sending attachments [the Botmaster way] is not yet supported on Slack as of version 2.2.3. However, Slack supports url unfurling (meaning if you send images and other types of media urls in your message, this will be shown in the messages and users won't just see a url). Also, because of how Botmaster is built (i.e. keep all information from the original message) you can find all the necessary information in the update.raw object of the update.

License

This library is licensed under the MIT license