# 4. Alert Interactions

When your application is ready to perform dispatch operations on an alert, your application should use the following API requests.

## 4.1 Update Status

This request updates the status of alerts received by your application. The following table describes:
- Alert statuses
- Statuses to which an ECC may transition alerts
- Statuses to which others (RapidSOS, Service Providers, Central Monitoring) may transition alerts

|Status|Description|ECC Transitions|Other Transitions
|-|-|-|-|
|DISPATCH_REQUESTED|The alert has been verified and sent to 911 by a trained RapidSOS Safety Agent. \\The alert should be transitioned to the ACKNOWLEDGED status immediately upon receipt to avoid timeout.|ACCEPTED, DECLINED, ACKNOWLEDGED|TIMEOUT, CANCELED
|ACCEPTED|The alert has been accepted by 911 and resources have been assigned to resolve the incident.|--|CANCELED|
|ACKNOWLEDGED|The alert has been acknowledged by 911. This is an intermediate state between ACCEPTED and DECLINED.|ACCEPTED, DECLINED|CANCELED|
|DECLINED|The alert has been declined by 911.|--|IGNORED|
|CANCELED|The alert has been canceled by the originating service provider or RapidSOS Safety Agent. Resources assigned to this incident may be released.|--|--|
|TIMEOUT|The alert was not transitioned from DISPATCH_REQUESTED within the allotted time. A phone call will be placed to 911 by the dispatching RapidSOS Safety Agent.|--|--|
|IGNORED|The alert was ignored by the receiving RapidSOS Safety Agent.|--|--|

> To prevent data staleness and preserve alert urgency, alerts will time out if not acknowledged in their allotted time frame.
>
> For this reason, you should transition the alert to ACKNOWLEDGED as soon as it is received. From there, the ECC may choose to accept or decline the alert.
>
> If you receive a TIMEOUT event for an alert, a phone call will be placed to your agency as a fail-safe mechanism. In this case, you should discard the alert from your system.

> If you find the above list of statuses incomplete or insufficient to complete your integration, please contact us by going to our support portal at support.rapidsos.com or by emailing <support@rapidsos.com>.

A sample request looks as follows:
```http
PATCH /v1/alerts/alert-6e58d630-d28f-4623-ba01-3207b497a9ba HTTP/1.1
Host: edx-sandbox.rapidsos.com
Authorization: Bearer YOUR-HTTP-ACCESS-TOKEN

{
  "status": "ACCEPTED",
}
```

A sample response looks as follows:
```json lineNumbers
{
  "status": {
    "name": "ACCEPTED",
    "display_name": "Accepted"
  },
  "last_updated_time": 1671736239735
}
```

> **API Documentation**
> 
> To view full documentation for this API request, try it out, or obtain code examples, check out our [Interactive API Explorer](https://rapidsos.portal.swaggerhub.com/alerts/default/alert-management-api-v-1-1-0#/default/patch__alert_id_).

## 4.2 Update Disposition

This operation updates the disposition of alerts accepted by your application. The following table summarizes the available dispositions.

> Alert disposition may only be set when an alert is being updated to ACCEPTED status, or when an alert is already in ACCEPTED status.

|Disposition|Description|
|-|-|
|DISPATCHED|Resource have been dispatched for the incident
|ENROUTE|Resources are en route to the incident location
|PREEMPTED|Dispatched resources were called off for either a higher priority event or other reason
|ON_SCENE|Resources are on scene at the incident location
|CLEARED_NO_REPORT|The incident has been cleared as a false alarm
|CLEARED_WITH_REPORT|The incident has been cleared as a valid alarm
|CLOSED|The incident has been completely resolved

> If you find the above list of dispositions incomplete or insufficient to complete your integration, please contact us by going to our support portal at support.rapidsos.com or by emailing <support@rapidsos.com>.

A sample request looks as follows:
```http
PATCH /v1/alerts/alert-6e58d630-d28f-4623-ba01-3207b497a9ba HTTP/1.1
Host: edx-sandbox.rapidsos.com
Authorization: Bearer YOUR-HTTP-ACCESS-TOKEN

{
  "disposition": "DISPATCHED",
}
```

A sample response looks as follows:
```json lineNumbers
{
  "disposition": {
    "name": "DISPATCHED",
    "display_name": "Dispatched"
  },
  "last_updated_time": 1671736239735
}
```

> **API Documentation**
> 
> To view full documentation for this API request, try it out, or obtain code examples, check out our [Interactive API Explorer](https://rapidsos.portal.swaggerhub.com/alerts/default/alert-management-api-v-1-1-0#/default/patch__alert_id_).

## 4.3 Create Log Message

This operation creates a log message for an incident and sends it to all parties involved with the emergency response. Log messages are all messages sent or received for a given alert.

> After creating a new log message for an alert you will receive a notification for that event type via your connection to the WebSocket Events API. Your application must de-duplicate notifications from the WebSocket Events API when your application is the sender of the message.
>
>For example, if you send a `chat_message` log message, you will receive an `alert.chat` event if you are subscribed to `alert.chat` events. 
>

|Message Type|Event Produced|
|-|-|
|CHAT_MESSAGE| `alert.chat`|
|SYSTEM_MESSAGE| `alert.disposition_update`|
|STATUS_UPDATE| `alert.status_update`|
|MILESTONE| `alert.milestone`
|MULTI_TRIP_SIGNAL| `alert.multi_trip_signal`|

A sample request looks as follows:
```http
POST /v1/alerts/alert-6e58d630-d28f-4623-ba01-3207b497a9ba/log_messages HTTP/1.1
Host: edx-sandbox.rapidsos.com
Authorization: Bearer YOUR-HTTP-ACCESS-TOKEN

{
  "message": "Hello world!",
  "message_type": "CHAT_MESSAGE",
  "sender": "John Doe",
  "sender_id": "RapidSOS-41"
}
```

A sample response looks as follows:
```json lineNumbers
{
  "alert_id": "alert-6e58d630-d28f-4623-ba01-3207b497a9ba",
  "message": "Hello world!",
  "message_type": "CHAT_MESSAGE",
  "sender": "John Doe",
  "sender_id": "RapidSOS-41",
  "entity_display_name": "Acme Alerts Inc.",
  "created_at": 1671736239735
}
```

> **API Documentation**
> 
> To view full documentation for this API request, try it out, or obtain code examples, check out our [Interactive API Explorer](https://rapidsos.portal.swaggerhub.com/alerts/default/alert-management-api-v-1-1-0#/default/post__alert_id__log_messages).
---
### [Continue to Step 5: Location Validation](https://rapidsos.portal.swaggerhub.com/alerts/default/location-validation)
