Skip to content

Moleculer Framework Addons: Send Messages, Photos, and Documents to Telegram using Telegram Bot API

License

Notifications You must be signed in to change notification settings

andreyunugro/moleculer-telegram-bot

Repository files navigation

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

Property Type Default Description
telegramToken String required Telegram Bot API Token. Visit How do I create a bot?.
telegramTarget String | Number - Telegram chat id as default target

Actions

sendMessage

Send a Telegram Message

Parameters

Property Type Default Description
message String required Message text
to String | Number - Message target (required if default target not set)
parse_mode String - Optional parse mode
disable_web_page_preview Boolean - Optional disable web page preview
disable_notification Boolean - Optional disable notification
reply_to_message_id Number - Optional reply to message id
reply_markup Any - Optional reply markup

sendPhoto

Send a Telegram Photo using URL.

Parameters

Property Type Default Description
photo String required Photo URL
to String | Number - Photo target (required if default target not set)
parse_mode String - Optional parse mode
caption String - Optional photo caption
disable_notification Boolean - Optional disable notification
reply_to_message_id Number - Optional reply to message id
reply_markup Any - Optional reply markup
fileOpts.filename String - Optional filename
fileOpts.contentType String - Optional file content type

sendDocument

Send a Telegram Document using URL.

Parameters

Property Type Default Description
doc String required Document URL
to String | Number - Document target (required if default target not set)
parse_mode String - Optional parse mode
caption String - Optional document caption
disable_notification Boolean - Optional disable notification
reply_to_message_id Number - Optional reply to message id
reply_markup Any - Optional reply markup
fileOpts.filename String - Optional filename
fileOpts.contentType String - Optional file content type

Methods

sendMessage

Send a message

Parameters

Property Type Default Description
to String | Number - Message target
message String - Body of the message
opts TelegramBot.SendMessageOptions - Send message options

sendPhoto

Send a photo

Parameters

Property Type Default Description
to String | Number - Message target
photo String | Stream | Buffer - Photo to send
opts TelegramBot.SendPhotoOptions - Send photo options
fileOpts TelegramBot.fileOpts - Send photo file options

sendDocument

Send a document

Parameters

Property Type Default Description
to String | Number - Message target
doc String | Stream | Buffer - Document to send
opts TelegramBot.SendDocumentOptions - Send document options
fileOpts TelegramBot.fileOpts - Send document file options

Test

npm test

In development with watching

npm run ci

License

The project is available under the MIT license.

About

Moleculer Framework Addons: Send Messages, Photos, and Documents to Telegram using Telegram Bot API

Topics

Resources

License

Stars

Watchers

Forks