# Listening to Alerts

Canonical page: https://www.adaptabletools.com/docs/handbook-alerting-alert-fired-event

- Event published by AdapTable whenever an [Alert](https://www.adaptabletools.com/docs/handbook-alerting/index.md) has been triggered by AdapTable
- Provides details of the Alert that fired and the Alert Definition that triggered it

The **Alert Fired Event** is published by AdapTable whenever an Alert is fired.

The `EventInfo` includes full details of the Alert Definition that triggered the Alert, the Change that occurred in AG Grid and other related information.

The change that triggered the alert can be one of two types:
- `Cell Change` - the value of a Cell has changed
- `Row Change` - a row has been added, updated, or deleted

The Alert Fired payload is in the [Alerts Technical Reference](https://www.adaptabletools.com/docs/technical-reference-alerting/index.md#alert-fired-event)

**Example: Events: Alert Fired**

Event published when Alerts fire

- This Demo listens to the Alert Fired Event and sends details as a System Status Message.  There are 2 Alerts: 
  - **Cell Changed**: `Error` Alert if *GitHub Stars* Column is `LessThan` 1000
  - **Row Changed**: `Warning` Alert when a Row is deleted

- Trigger Alerts and then see how the Alert Fired Event is handled by:
  - Editing a cell in the _GitHub Stars_ Column to a value `<1000`
  - Clicking the Delete Row Button

Demo project (Vanilla); the files without a marker are shown below:

```text
src/
  adaptableOptions.ts
  agGridModules.ts     [template]
  columnDefs.ts        [template]
  gridOptions.ts       [template]
  index.ts             [template]
  onAdaptableReady.ts
  rowData.ts           [template]
  styles.css           [template]
index.html             [template]
package.json           [template]
tsconfig.json          [template]
```

Files marked `[template]` are the same in every demo; see the [demo template](https://www.adaptabletools.com/llms/demo-template.md#vanilla).

**`src/adaptableOptions.ts`**

```ts
import {AdaptableOptions} from '@adaptabletools/adaptable';
import {WebFramework} from './rowData';

export const adaptableOptions: AdaptableOptions<WebFramework> = {
  primaryKey: 'id',
  adaptableId: 'Alert Fired Event Demo',
  actionColumnOptions: {
    actionColumns: [
      {
        columnId: 'action',
        friendlyName: 'Delete',
        controls: [{type: 'command', command: 'delete'}],
      },
    ],
  },
  initialState: {
    Dashboard: {
      ModuleButtons: ['Alert'],
      Tabs: [
        {
          Name: 'Toolbars',
          Toolbars: ['Alert', 'SystemStatus'],
        },
      ],
    },
    StatusBar: {
      StatusBars: [
        {
          Key: 'Center Panel',
          StatusBarPanels: ['Alert', 'SystemStatus'],
        },
      ],
    },
    Theme: {CurrentTheme: 'dark'},
    Alert: {
      AlertDefinitions: [
        {
          Name: 'alert-error-github-stars',
          MessageType: 'Error',
          Scope: {
            ColumnIds: ['github_stars'],
          },
          Rule: '[github_stars] < 1000',
          AlertProperties: {
            HighlightCell: true,
            DisplayNotification: true,
          },
        },
        {
          Name: 'alert-warning-row-removed',
          Rule: 'ROW_REMOVED{}',
          MessageType: 'Warning',
          MessageHeader: 'You removed a row',
          MessageText: 'Hey! A row was removed',
          Scope: {
            All: true,
          },
          AlertProperties: {
            DisplayNotification: true,
          },
        },
      ],
    },
    Layout: {
      CurrentLayout: 'Standard Layout',
      Layouts: [
        {
          Name: 'Standard Layout',
          TableColumns: [
            'action',
            'name',
            'language',
            'github_stars',
            'license',
            'open_issues_count',
            'description',
            'created_at',
            'has_wiki',
            'updated_at',
            'pushed_at',
            'github_watchers',
          ],
          AutoSizeColumns: true,
        },
      ],
    },
  },
};
```
**`src/onAdaptableReady.ts`**

```ts
import {AdaptableReadyInfo} from '@adaptabletools/adaptable';
import {AdaptableMessageType, AlertFiredInfo} from '@adaptabletools/adaptable';

export const onAdaptableReady = ({adaptableApi}: AdaptableReadyInfo) => {
  adaptableApi.eventApi.on('AlertFired', (alertFiredInfo: AlertFiredInfo) => {
    const messageType: AdaptableMessageType =
      alertFiredInfo.alert.alertDefinition.MessageType;
    if (messageType == 'Info') {
      adaptableApi.systemStatusApi.setInfoSystemStatus(
        alertFiredInfo.alert.alertType,
        alertFiredInfo.alert.alertDefinition.MessageHeader
      );
    } else if (messageType == 'Success') {
      adaptableApi.systemStatusApi.setSuccessSystemStatus(
        alertFiredInfo.alert.alertType,
        alertFiredInfo.alert.alertDefinition.MessageHeader
      );
    } else if (messageType == 'Warning') {
      adaptableApi.systemStatusApi.setWarningSystemStatus(
        alertFiredInfo.alert.alertType,
        alertFiredInfo.alert.alertDefinition.MessageHeader
      );
    } else if (messageType == 'Error') {
      adaptableApi.systemStatusApi.setErrorSystemStatus(
        alertFiredInfo.alert.alertType,
        alertFiredInfo.alert.alertDefinition.MessageHeader
      );
    }
  });
};
```
