1.1.5 • Published 10 months ago

noti_bot v1.1.5

Weekly downloads
10
License
ISC
Repository
github
Last release
10 months ago

noti_bot

send notifications to slack, telegram

Install

https://www.npmjs.com/package/noti_bot

npm install noti_bot

Setup

  • Slack:

    • Go to Incoming webhook setting
    • Add to Slack
    • At Post to Channel section, select channel or username want to receive message
    • Add Incoming webhook integration
    • Copy webhook URL
    • Your SLACK_HOOK_KEY is all text following https://hooks.slack.com/services/ example: T04BK8XKDPH/B04SA4ZCT45/EuvIUglFNNkEJIPlKRyGNH5K
  • Telegram:

    • Go to @BotFather
    • /start to create your bot
    • Save your bot's token
    • If you would like to get direct message from bot, send message to bot first to activate (otherwise, telegram will make your message is spam and won't deliver to your user)
    • If you would like to post message to a group, invite bot to that group
    • Run a bot instance to answer to user their TELEGRAM_CHAT_ID

      using /mytelegramid

      const Promise = require('bluebird')
          Promise.config({
          cancellation: true,
      })
      const TelegramBot = require('node-telegram-bot-api')
      // replace the value below with the Telegram token you receive from @BotFather
      const token = process.env.TOKEN
      // Create a bot that uses 'polling' to fetch new updates
      const bot = new TelegramBot(token, {
      polling: true,
      })
bot.onText(/\/mytelegramid/, async (msg, match) => {
    let res = `Your telegram id is ${msg.from.id}`
    if (msg.chat.id != msg.from.id) {
        res += `\n Your group chatId: ${msg.chat.id}`
    }
    bot.sendMessage(msg.chat.id, res, {
        reply_to_message_id: msg.message_id,
    })
})
```

Usage

    const noti_bot = require('noti_bot')
    const notifyTelegram = noti_bot.telegram
    const notifySlack = noti_bot.slack
    const notifyDiscord = noti_bot.discord
    
    // enable isHtmlMode = true if you send rich text
    notifyTelegram(msg, TELEGRAM_BOT_TOKEN, TELEGRAM_TARGET_CHAT_ID , isHtmlMode)

    // convert msg to markdown format if you want to send rich text
    notifySlack(msg, SLACK_HOOK_KEY, SLACK_CHANNEL, SLACK_BOTNAME, SLACK_BOT_ICON)

    // convert msg to markdown format if you want to send rich text
    notifyDiscord(msg, webhook)
1.1.5

10 months ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.1

4 years ago

1.1.1-a

4 years ago

1.1.2

4 years ago

1.1.0

4 years ago

1.0.7

4 years ago

1.0.6-beta

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

6 years ago