---
name: kimaai_chatbot_csat_saved
type: action
since: 1.6.0
tier: free
feature: feedback
area: chatbot
summary: Fires when a visitor's rating of a whole conversation, one to five stars, was saved.
parameters:
  - name: session_id
    type: string
    description: The conversation's session ID.
  - name: rating
    type: int
    description: 1 to 5 stars.
  - name: comment
    type: string
    description: The visitor's comment, or empty.
---

# kimaai_chatbot_csat_saved

## When it fires

When the visitor sends the rating at the end of a chat (`POST /wp-json/kimaai/v1/chatbot/feedback/csat`), after it was checked and stored. The widget asks for it when the visitor closes the chat or starts a new conversation after at least three answers, if the satisfaction survey is on. A rating is refused, and the action does not fire, when it is not 1 to 5, the conversation belongs to another account, has no messages or was rated already: each conversation takes one rating.

KimaAI hooks it itself for the conversation insights. The comment is the visitor's own text and can contain personal data.

## Example

```php
add_action(
  'kimaai_chatbot_csat_saved',
  function (string $session_id, int $rating, string $comment): void {
    if ($rating > 2) {
      return;
    }

    wp_mail(
      get_option('admin_email'),
      sprintf('A chat was rated %d of 5', $rating),
      $comment !== '' ? $comment : 'No comment.'
    );
  },
  10,
  3
);
```

## Related

- `kimaai_chatbot_message_feedback_saved`: fires for the rating of a single answer.
