1.0.0 • Published 1 year ago
@apifonica/notifier v1.0.0
Example usage:
Initialize
import { Telegram, Slack } from "@apifonica/notifier"
// initialize with authorization access token for telegram bot
const telegram = new Telegram({
accessToken: '123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11',
})
// initialize with authorization access token for slack app
const slack = new Slack({
accessToken: 'xoxb-123456789101-1234567891011-ABCDEFghijklmnoPQr1stuvw',
})
How to create and setup bot for Telegram see here https://core.telegram.org/bots/api#authorizing-your-bot.
How to create and setup app for Slack see here https://api.slack.com/authentication/basics.
Send message
// for sending messages to Telegram required options are "chat_id" and "text"
// other options which provide to use Telegram API are optional
const telegramMessage = await telegram.sendMessage({
chat_id: '-123456789',
text: 'Hello World',
parse_mode: 'HTML',
disable_web_page_preview: true,
})
console.log(`telegramMessage: ${JSON.stringify(telegramMessage)}`)
// for sending messages to Slack required options are "channel" and "text"
// other options which provide to use Slack API are optional
const slackMessage = await slack.postMessage({
channel: 'ABC12345XYZ',
text: 'Hello World',
blocks: [
{
type: 'section',
text: {
type: 'mrkdwn',
text: 'Hey, nice to meet you'
}
},
]
})
console.log(`slackMessage: ${JSON.stringify(slackMessage)}`)
1.0.0
1 year ago