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

@cloudrac3r/in-your-element

v1.0.0

Published

A single file modern Matrix Application Service library written in JavaScript for Node.js, built on the h3 web server.

Downloads

19

Readme

In Your Element

A single file modern Matrix Application Service library written in JavaScript for Node.js, built on the h3 web server.

This is used in production by the Out Of Your Element Matrix-Discord bridge.

Example

Synapse needs an registration.yaml file to talk to your application service. You should create one according to the Synapse documentation and link it in to your Synapse configuration.

Then you can use In Your Element. Start with this example:

const {AppService} = require("@cloudrac3r/in-your-element")
const config = {
  url: "http://localhost:4873", // port for In Your Element to listen on; should be the same URL as in registration.yaml
  hs_token: "2a38549b2901ef759" // random string for authentication; should be the same hs_token as in registration.yaml
}
const as = new AppService(config).listen()

as.on("type:m.room.message", event => {
  // this function will be called every time a m.room.message event arrives
})

API Documentation

Config

  • url: string
    • In Your Element will listen on this URL's port.
  • listen: optional number/string
    • If provided, url is ignored. Custom port or UNIX socket to listen on.
  • hs_token: string
    • The homeserver should use the same token for all requests. This verifies that incoming requests came from the homeserver.

Events

The AppService is an EventEmitter.

As per the above example, you can use .on(<name>, event => { ... to listen for incoming events.

  • <name> is type:<event type> to listen for specific types of Matrix events and/or state events
    • for example, <name> is type:m.room.message to listen for room message events
    • for example, <name> is type:m.room.avatar to listen for the room's avatar changing
  • <name> is ephemeral_type:<event type> for listen for specific ephemeral Matrix events
    • for example, <name> is ephemeral_type:m.typing to listen for typing start/stop events
  • <name> is event to listen for ANY Matrix event and/or state event in the same listener function
  • <name> is ephemeral to listen for ANY ephemeral event in the same listener function

Queries

as.roomQueryCallback = async alias => {
  // please read https://spec.matrix.org/v1.11/application-service-api/#querying
  // called when somebody looks up an unregistered room in the appservice's namespace
  // you must return true if you created the room for the alias during the function invocation
  // you must return false if you didn't
}

as.userQueryCallback = async mxid => {
  // please read https://spec.matrix.org/v1.11/application-service-api/#querying
  // called when somebody looks up an unregistered user in the appservice's namespace
  // you must return true if you created the user account for mxid during the function invocation
  // you must return false if you didn't
}

Client-Server API

In Your Element does not provide any helpers for the Matrix Client-Server API. In other words, if you want to make requests to the homeserver as your application service, you will have to add a library like matrix-js-sdk, or write the code yourself.