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

larkjs-messenger

v0.0.12

Published

**For Context this library is used for sending message card on larksuite Messenger, this would save your time building json strings just of the layout of your message card**

Downloads

13

Readme

Lark bot Message Card Builder

For Context this library is used for sending message card on larksuite Messenger, this would save your time building json strings just of the layout of your message card

To get Started

You need to install the necessary third-party libaries to make things work

  1. Axios
  2. Form-Data

Copy this line to your terminal to install these libraries

npm i axios form-data

Features

  • Sends Message easily
  • Automatic JSON Builder
  • No manual uploads of image

Documentation

Import the libaries following its methods and classes

import { ButtonType, Colors, MessageCard } from "./lark_msgcard/src/messageCard";
import { Credentials, MsgType, Token } from "./lark_msgcard/src/token";
const creds = new Credentials();

Initialize your

app_id and app_secret

creds.app_id = '<app_id_here>';
creds.app_secret = '<app_secret_here>';

Optional instance when using image

img_path_file

creds.img_path_file = '<image_file_path>';

Create instance on Token class passing the value of Credentials class

const lark = new Token(creds);

By doing this, you're adding your initializations value to Token class to generate tenant_token

Generate tenant_token

const token = await lark.generateToken();

For generating tenant_token it returns promises and needed to use await so it's necessary to enclose to asynchronous function just like this

(async() => {
  const token = await lark.generateToken();
)()

Message Card

You need to create instance of Message Card class and call every methods you needed

  const msgCard = new MessageCard();

The problemm here that if you call directly the msgCard instance you will get the incorrect value of JSON string which has "data" object that suposedly not to be included when making message card, so to fix this you then to assign the instance to variable and just call the method just like this

  const json = msgCard.generate().message_type().generate().card().config(true, true)

The .config(boolean, boolean) method is sets the default value as true which means it will dynamically adjust its width and height depending on the window size

Header

Adding header is Optional but you can do it like this

  const json = msgCard.generate().message_type()
        .generate().card().config(true, true)
        .generate().card().header("This is Header", Colors.blue) //First Argument is the content of your header and Second Argument represent as color

Elements

The Elements is where the card contents wrap in there are many types of value you can put inside Elements These are the following

  • Fields
  • Description
  • Image
  • Button
  • Horizontal line etc...

Element values

const json = msgCard.generate().message_type()
       .generate().card().config(true, true)
       .generate().card().header("PIF COLLECTION PIPELINE UPDATE", Colors.blue)
       .generate().card().elements(
           msgCard.image(img_key,"This is Image Description"),
           msgCard.description("Hi <at id=all></at>,\n This is description"),
           msgCard.hr(),
           msgCard.fields(["Value 1", "Value 2", "Value 3", "Value 4"]),
           msgCard.extra(msgCard.description("Extra Description"), msgCard.button("https://www.example.com", "Download", ButtonType.regular)), //Button types Regular, Danger and Primary
           msgCard.hr(),
           msgCard.description("This is Description")
       ).generate().card().build();

Send the Message Card

 lark.sendMsg(json, token,"<your_email_here>")

Note as other markdown like:

  • Hyperlink
  • Bold
  • Italic

You can do the same..

Generating Image Key


   //Initialize image path
   creds.img_path_file = "<image_file_path_here>";

   // Creating intance of Token passing value being declared on creds
   const lark = new Token(creds);
   
   const token = await lark.generateToken(); //Generates token
   const img_key = await lark.uploadImg(token); //Using token to upload image to lark server

Please take note that this is not the official library of larksuite messenger

For full documentation visit Larksuites Official Documentation