1.2.14 • Published 6 months ago

@iamnnort/telegraf-helper v1.2.14

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

Info

Helpers for Telegraf.js framework - Simple - Customizable - Convenient

Installation

NPM

npm install @iamnnort/telegraf-helper

Yarn

yarn add @iamnnort/telegraf-helper

Usage

messageHelper.makeMessage

Make well formatted messages with header and body sections.

Example

import { messageHelper } from "@iamnnort/telegraf-helper";

const message = messageHelper.makeMessage({
  header: [
    {
      title: "Telegraf Helper",
      subtitle: "Make your code smaller",
    },
  ],
  body: ["Simple", "Customizable", "Convenient"],
});

Log

<b>Telegraf Helper</b>: Make your code smaller

Simple
Customizable
Convenient

Parameters

ParameterDescription
headerList of configs for the header section
header[i].titleTitle of the header
header[i].subtitleAdditional title of the header
bodyList of strings of the body section

messageHelper.makeEntityMessage

Make well formatted messages for a given entity.

Example

import { messageHelper } from "@iamnnort/telegraf-helper";

const entityMessage = messageHelper.makeEntityMessage({
  title: "Telegraf Helper",
  comment: "All the Best",
  fallback: "Oops",
  properties: [
    {
      name: "Complexity",
      value: "Simple",
    },
    {
      name: "Flexibility",
      value: "Customizable",
    },
    {
      name: "Usability",
      value: "Convenient",
    },
  ],
});

Log

<b>Telegraf Helper:</b>

— <i>Complexity:</i> Simple
— <i>Flexibility:</i> Customizable
— <i>Usability:</i> Convenient

All the Best

Parameters

ParameterDescription
titleTitle of the entity block shown at the top
commentComment of the entity block shown at the bottom
fallbackFallback if properties are empty or missing
propertiesList of configs for the entity properties
properties[i].nameName of the property
properties[i].valueValue of the property

messageHelper.formatMessage

Format message by transforming custom tags to HTML analogs.

Example

import { messageHelper } from "@iamnnort/telegraf-helper";

const formattedMessage = messageHelper.formatMessage("[b]Telegraf Helper[b]");

// <b>Telegraf Helper</b>

Transform map

ParameterDescription
[b]Example[b]<b>Example</b>
[i]Example[i]<i>Example</i>
[u]Example[u]<u>Example</u>
[t]Example[t]<s>Example</b>
[s]Example[s]<tg-spoiler>Example</tg-spoiler>
[c]Example[c]<code>Example</code>
[a]Example=https://example.com[a]<a href="https://example.com">Example</a>

telegramHelper.getBotId

Retrieve the identifier for a given token.

Example

import { telegramHelper } from "@iamnnort/telegraf-helper";

const botId = telegramHelper.getBotId("<bot token>");

// 6607146717

telegramHelper.makeInlineLink

Make the inline link for a given username.

Example

import { telegramHelper } from "@iamnnort/telegraf-helper";

const inlineLink = telegramHelper.makeInlineLink("iamnnort");

// @iamnnort

telegramHelper.makeLink

Make the external link for a given username.

Example

import { telegramHelper } from "@iamnnort/telegraf-helper";

const link = telegramHelper.makeLink("iamnnort");

// https://t.me/iamnnort

Telegram

Make Telegram instance from Telegraf with additional useful functions like sendSmart.

Example

import { Telegram } from "@iamnnort/telegraf-helper";

const telegram = new Telegram("<bot token>");

await telegram.sendSmart(TelegramMessageTypes.TEXT, "iamnnort", {
  text: "<text>",
});

await telegram.sendSmart(TelegramMessageTypes.PHOTO, "iamnnort", {
  text: "<text>",
  media: "<photo ID or URL>",
});

License

This project is licensed under the MIT license. See the LICENSE file for more info.

1.2.14

6 months ago

1.2.13

6 months ago

1.2.11

6 months ago

1.2.10

6 months ago

1.2.9

6 months ago

1.2.8

6 months ago

1.2.7

6 months ago

1.2.6

7 months ago

1.2.5

7 months ago

1.2.4

7 months ago

1.2.1

7 months ago

1.1.11

7 months ago

1.1.10

7 months ago

1.1.9

7 months ago

1.1.8

7 months ago

1.1.7

7 months ago

1.1.6

7 months ago

1.1.5

7 months ago

1.1.4

7 months ago

1.1.3

7 months ago

1.1.2

7 months ago

1.1.1

7 months ago

1.1.0

7 months ago

1.0.5

7 months ago

1.0.3

7 months ago

1.0.2

7 months ago

1.0.1

7 months ago