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 🙏

© 2026 – Pkg Stats / Ryan Hefner

direqt

v1.7.0

Published

Node.js library for the Direqt API

Readme

Direqt Node.js Library


The Direqt Node.js library provides access to the messaging capabilities supported by the Direqt platform.

:warning: This library is meant for server-side usage only. Do not use it in client-side (browser) code, as it would expose your secret access token.

Installation

$ npm install direqt

Usage

The library needs to be configured with your chatbot's secret access token and signing secret, which are available in the Direqt Developer Console. Here's an example of initializing the library:

import { DireqtApi } from 'direqt';
const direqt = new DireqtApi({
    accessToken: YOUR_ACCESS_TOKEN,
    signingSecret: YOUR_SIGNING_SECRET
})

Receiving messages from users

Your chatbot is notified of messages from users via a webhook. The provide the URL of your webhook in the "Webhook" settings associated with your chatbot in the Direqt Developer console.

Webhooks are invoked with a simple POST request, giving you access to information about the sender and their message. Here's a simple webhook that captures the text sent by a user and writes it to the console:

function myDireqtWebhook(req: Request, res: Response) {
    const { userId, userMessage } = req.body;
    const text = userMessage.content?.text;
    if (text) {
        console.log(`${userId}: ${text}`);
        /* process the message here */
    }
    res.sendStatus(200);
}

(Note that there are other types of messages that may be delivered to your webhook, but simple messaging apps seldom need to deal with them. We suggest you implement your webhook like the example above, and ignore any message without userMessage.content.text defined.)

Before you process messages directed at your webhook, you should verify the request signature associated with the request to be sure it originated from Direqt. You can do this with the verifyMiddleware provided by the DireqtApi object:

const app = express();

// the raw request body is required for signature verification
const rawBodyExtractor = (req, res, buf) => {
    req.rawBody = buf.toString();
};
app.post('/webhook', 
    express.json({ verify: rawBodyExtractor }),
    direqt.messaging.verifyMiddleware(),
    myDireqtWebhook
    );

Sending messages

To send a text message to a user, provide the userId (the same value you obtained when the user sent a message to your webhook) and the text to send to the sendTextMessage method:

const result = await direqt.messaging.sendTextMessage(
    userId, 'Hello from my chatbot!');

You can also send other types of content to users, such as cards, carousels, and other rich messaging elements. The Direqt Messaging API defines the format of these messages, which can be sent using the sendContentMessage and sendActionMessage methods:

const result = await direqt.messaging.sendContentMessage(
    userId, 
    { 
        contentType: 'file',
        file: {
            url: 'https://www.example.com/foo.png'
        }
    });

Sample code

See the ./samples/ folder for sample bot implementations.

Copyright (c) 2023 Direqt Inc.