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

@deltachat/napi-jsonrpc

v0.101.1

Published

Allows you to use Deltachat core from nodejs. You can use this library to create Bots and Clients for deltachat. This package aims to become the sucessor to `deltachat-node`, replacing it as a backend in deltachat desktop.

Downloads

4

Readme

Deltachat jsonrpc-napi bindings

Allows you to use Deltachat core from nodejs. You can use this library to create Bots and Clients for deltachat. This package aims to become the sucessor to deltachat-node, replacing it as a backend in deltachat desktop.

The main differences to deltachat-node are:

  • Exclusively use the jsonrpc api*:
    • easier to use, develop and maintain because it has better (autogenerated) typescript bindings.
    • better errors, functions throw errors, not a check if the function returned 0.
    • everything is async, no blocking calls
  • easier to install, maintain and less errors in the bindings levels because it's using napi-rs as base which is written in rust instead of the manually written c bindings in deltachat-node

* there might be some exceptions to expose certain low-level functions for deltachat-desktop.

Usage

  • If you use typescript, then you need to use a typescript version newer than 4.7.
  • Nodejs version 14 is the lowest supported node version by this package, but we recommend using 16 or newer.
  • This is an ESM module.

basic usage

npm i @deltachat/napi-jsonrpc
import { openDeltaChatInstance, T } from "@deltachat/napi-jsonrpc";

async function main() {
  const dc = await openDeltaChatInstance("./test-deltachat-tmp");
  // log all events to console
  dc.on("ALL", console.debug.bind("[core]"));

  // prepare account and login
  let firstAccount: T.Account | undefined = (await dc.rpc.getAllAccounts())[0];
  if (!firstAccount) {
    firstAccount = await dc.rpc.getAccountInfo(await dc.rpc.addAccount());
  }
  if (firstAccount.type === "Unconfigured") {
    await dc.rpc.batchSetConfig(firstAccount.id, {
      addr: process.env.ADDR,
      mail_pw: process.env.MAIL_PW,
    });
    await dc.rpc.configure(firstAccount.id);
  }

  // the actual bot code, echos back text messages you sent to it
  const botAccountId = firstAccount.id;
  const emitter = dc.getContextEvents(botAccountId);
  emitter.on("IncomingMsg", async ({ chatId, msgId }) => {
    const chat = await dc.rpc.getBasicChatInfo(botAccountId, chatId);
    // only echo to DM chat
    if (chat.chatType === 100 /* DC_CHAT_TYPE_SINGLE = 100 */) {
      const message = await dc.rpc.messageGetMessage(botAccountId, msgId);
      await dc.rpc.miscSendTextMessage(
        botAccountId,
        message.text || "",
        chatId
      );
    }
  });
}

use from a different process (like renderer process in electron)

TODO, Look at the deltachat-desktop code once it switches to this package for reference n the meantime.

Build the package yourself

Preparations

# install dependencies
yarn

Build it

yarn make

Update deltachat-core

to update deltachat core you need to update 2 packages:

  1. adjust the version in Cargo.toml:
deltachat-jsonrpc = { git = "https://github.com/deltachat/deltachat-core-rust/", version = "1.97.0" }
  1. run this command with the new version:
yarn add @deltachat/[email protected]

Publish new version:

The ci does this automatically, you just need to run.

# npm version [<newversion> | major | minor | patch | premajor | preminor | prepatch | prerelease | from-git]
npm version patch
git push --follow-tags