# Python \> Get post content if mentioned

**URL:** <https://meta.discourse.org/t/python-get-post-content-if-mentioned/248309>\
**Category:** Development\
**Tags:** mentions\
**Created:** [December 8, 2022, 6:49pm UTC](https://meta.discourse.org/t/python-get-post-content-if-mentioned/248309 "2022-12-08T18:49:25Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)\
**Post date:** [December 8, 2022, 11:51pm UTC](https://meta.discourse.org/t/python-get-post-content-if-mentioned/248309/4 "2022-12-08T23:51:14Z")

</div>

> [@MarcP](#):
>
> Generate reply with OpenAI

I’m assuming that what you want to do is generate a response from OpenAI when a given username (for example, `UserA`) is mentioned in a post. If that’s correct, instead of making API requests to Discourse to get the notifications, you could point a Discourse Notification Event webhook to your Python application’s server. The Python application would need to look at the webhook’s payload. If the payload’s `notification_type` was set to `1`, and its `user_id` matched the ID of the user you are interested in getting notifications for, you’d make an API request to Discourse to get the post that’s set in the payload’s `original_post_id` field. Then send the post content that’s returned from that request on to OpenAI.

Here’s an example of what the payload for a mention notification looks like:

```plaintext
{
  "notification": {
    "id": 55267,
    "user_id": 2,
    "notification_type": 1,
    "read": false,
    "high_priority": false,
    "created_at": "2022-12-08T23:23:36.379Z",
    "post_number": 5,
    "topic_id": 277,
    "fancy_title": "I should be able to call this topic anything",
    "slug": "i-should-be-able-to-call-this-topic-anything",
    "data": {
      "topic_title": "I should be able to call this topic anything",
      "original_post_id": 10999,
      "original_post_type": 1,
      "original_username": "scossar",
      "revision_number": null,
      "display_username": "scossar"
    }
  }
}

```

The benefit of this approach is that it would let you get notifications in real time - without having to make large numbers of API requests to your Discourse site.

If you go with the webhook approach, it would be a good idea to set the webhook’s “Secret” field on Discourse, then validate the request on your Python application to make sure that the secret key is correctly set. I haven’t tried setting up a route on a Python application to do this yet. Details about how to validate a webhook’s Secret on WordPress are here: [wp-discourse-custom-webhook-request/wp-discourse-custom-webhook-request.php at master · scossar/wp-discourse-custom-webhook-request · GitHub](https://github.com/scossar/wp-discourse-custom-webhook-request/blob/master/wp-discourse-custom-webhook-request.php#L78).

---

_[View the full topic](https://meta.discourse.org/t/python-get-post-content-if-mentioned/248309)._
