---
name: kimaai_chatbot_message_feedback_saved
type: action
since: 1.5.4
tier: free
feature: feedback
area: chatbot
summary: Fires when a visitor's rating of an answer, helpful or not, was saved.
parameters:
  - name: session_id
    type: string
    description: The conversation's session ID.
  - name: message_id
    type: string
    description: The ID of the rated answer in the chat history.
  - name: rating
    type: int
    description: 1 for helpful, -1 for not helpful.
  - name: comment
    type: string
    description: For not helpful, the reason the visitor picked and their comment, joined by a colon; empty for helpful.
---

# kimaai_chatbot_message_feedback_saved

## When it fires

When the visitor rates an answer with Helpful or Not helpful under it (`POST /wp-json/kimaai/v1/chatbot/feedback/message`), after the rating was checked and stored. A rating is refused, and the action does not fire, when the payload is invalid, the conversation belongs to another account, the answer does not exist in that conversation or it was rated already: each answer takes one rating.

KimaAI hooks it itself for the conversation insights and the human handoff (Pro), which can send a conversation with several ratings down to the team. The comment is the visitor's own text and can contain personal data.

## Example

```php
add_action(
  'kimaai_chatbot_message_feedback_saved',
  function (string $session_id, string $message_id, int $rating, string $comment): void {
    if ($rating !== -1) {
      return;
    }

    wp_remote_post(
      'https://hooks.slack.com/services/T000/B000/XXXX',
      [
        'headers' => ['Content-Type' => 'application/json'],
        'body' => wp_json_encode(['text' => 'An answer was rated not helpful: ' . ($comment !== '' ? $comment : 'no reason given')]),
      ]
    );
  },
  10,
  4
);
```

Replace the Slack address with your incoming webhook.

## Related

- `kimaai_chatbot_csat_saved`: fires for the rating of the whole conversation.
- `kimaai_chatbot_handoff`: fires when ratings sent a conversation to the team.
