Options
All
  • Public
  • Public/Protected
  • All
Menu

Class AlertManager

Handles alert notifications and silence requests

Hierarchy

  • AlertManager

Index

Constructors

constructor

Properties

Private alerts

alerts: Level<AlertsDBValue>

Private db

db: LevelGraph<BaseDBKey>

Private Readonly silenceButtons

silenceButtons: InlineKeyboardButton[]

Methods

addAlert

addAlertMessage

  • addAlertMessage(chatId: string, messageId: string, alertHash: string): Promise<void>
  • Links a message and the alert on the state

    Parameters

    • chatId: string

      telegram chat ID

    • messageId: string

      telegram message ID

    • alertHash: string

      hash from IAlert.hash

    Returns Promise<void>

    resolves if added successfully

addUserChat

  • addUserChat(userId: string, chatId: string): Promise<void>
  • Adds a user chat to the state

    Parameters

    • userId: string

      telegram user ID

    • chatId: string

      telegram chat ID

    Returns Promise<void>

    void on success or throws error

delAlert

  • delAlert(alertHash: string): Promise<void>

Private firingMessageMarkup

  • firingMessageMarkup(alert: IAlert): InlineKeyboardMarkup

getAlert

  • getAlert(alertHash: string): Promise<IAlert>

getAlertFromMessage

  • getAlertFromMessage(messageId: string): Promise<IAlertMessage | undefined>

getChats

getIdsFilteredBy

getMessagesByAlert

  • getMessagesByAlert(alertHash: string): Promise<IAlertMessage[]>

getUnalertedChats

  • getUnalertedChats(alertHash: string): Promise<(string | number)[]>
  • Gets all chats which haven't received the given alert

    Parameters

    • alertHash: string

      alert hash to search for

    Returns Promise<(string | number)[]>

    chats which didn't receive the alert

hasUserChat

  • hasUserChat(userId: string, chatId: string): Promise<boolean>
  • Check whether a given user chat is already on state

    Parameters

    • userId: string

      telegram user ID

    • chatId: string

      telegram chat ID

    Returns Promise<boolean>

    true if the chat exists on context state

processCallback

processSilence

sendAlertMessages

  • sendAlertMessages(alert: IAlert, telegram: Telegram): Promise<void>
  • sends firing alert messages, or edits messages with resolved status

    Parameters

    • alert: IAlert

      alert data

    • telegram: Telegram

      telegram object

    Returns Promise<void>

    callback chain result

Static silenceAlert

  • silenceAlert(alert: IAlert, time: string, username?: undefined | string, comment?: undefined | string): Promise<Response>
  • Silence an alert

    Parameters

    • alert: IAlert

      the alert to silence

    • time: string

      period to silence the alert, e.g. "1h"

    • Optional username: undefined | string

      silence requester

    • Optional comment: undefined | string

    Returns Promise<Response>

    request response

Static Private silenceCallbackData

  • silenceCallbackData(duration: string): string
  • generates callback data to silence an alert

    Parameters

    • duration: string

      string representing time, e.g. 1h

    Returns string

    data encoded as string

Generated using TypeDoc