1.1.1 • Published 3 years ago

moleculer-telegram-bot v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

moleculer-telegram-bot

Send Messages, Photos, and Documents to Telegram using Telegram Bot API with node-telegram-bot-api module.

unittest Coverage Status Codacy Badge Codacy Badge

Install

npm install moleculer-telegram-bot --save

Usage

Before use the example below, please set the TELEGRAM_TOKEN environment variables and optional TELEGRAM_TARGET for default target.

const { ServiceBroker } = require('moleculer');
const TelegramService = require('moleculer-telegram-bot');

// Create broker
const broker = new ServiceBroker({ logger: console });

// Load my service
broker.createService({
    name: 'telegram',
    mixins: [TelegramService()]
});

// Start server
broker.start().then(() => {
  broker
    .call('telegram.sendMessage', { message: 'Hello Telegram!' })
    .then(res => console.log('Telegram message sent.'))
    .catch(console.error);
});

Settings

PropertyTypeDefaultDescription
telegramTokenStringrequiredTelegram Bot API Token. Visit How do I create a bot?.
telegramTargetString | Number-Telegram chat id as default target

Actions

sendMessage

Send a Telegram Message

Parameters

PropertyTypeDefaultDescription
messageStringrequiredMessage text
toString | Number-Message target (required if default target not set)
parse_modeString-Optional parse mode
disable_web_page_previewBoolean-Optional disable web page preview
disable_notificationBoolean-Optional disable notification
reply_to_message_idNumber-Optional reply to message id
reply_markupAny-Optional reply markup

sendPhoto

Send a Telegram Photo using URL.

Parameters

PropertyTypeDefaultDescription
photoStringrequiredPhoto URL
toString | Number-Photo target (required if default target not set)
parse_modeString-Optional parse mode
captionString-Optional photo caption
disable_notificationBoolean-Optional disable notification
reply_to_message_idNumber-Optional reply to message id
reply_markupAny-Optional reply markup
fileOpts.filenameString-Optional filename
fileOpts.contentTypeString-Optional file content type

sendDocument

Send a Telegram Document using URL.

Parameters

PropertyTypeDefaultDescription
docStringrequiredDocument URL
toString | Number-Document target (required if default target not set)
parse_modeString-Optional parse mode
captionString-Optional document caption
disable_notificationBoolean-Optional disable notification
reply_to_message_idNumber-Optional reply to message id
reply_markupAny-Optional reply markup
fileOpts.filenameString-Optional filename
fileOpts.contentTypeString-Optional file content type

Methods

sendMessage

Send a message

Parameters

PropertyTypeDefaultDescription
toString | Number-Message target
messageString-Body of the message
optsTelegramBot.SendMessageOptions-Send message options

sendPhoto

Send a photo

Parameters

PropertyTypeDefaultDescription
toString | Number-Message target
photoString | Stream | Buffer-Photo to send
optsTelegramBot.SendPhotoOptions-Send photo options
fileOptsTelegramBot.fileOpts-Send photo file options

sendDocument

Send a document

Parameters

PropertyTypeDefaultDescription
toString | Number-Message target
docString | Stream | Buffer-Document to send
optsTelegramBot.SendDocumentOptions-Send document options
fileOptsTelegramBot.fileOpts-Send document file options

Test

npm test

In development with watching

npm run ci

License

The project is available under the MIT license.