# Creating custom notifications

**URL:** https://meta.discourse.org/t/creating-custom-notifications/58950
**Category:** Development
**Created:** [March 13, 2017, 3:29am UTC](https://meta.discourse.org/t/creating-custom-notifications/58950 "2017-03-13T03:29:35Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![rimian](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rimian/32/120658_2.png) [@rimian](https://meta.discourse.org/u/rimian)
#### Post date: [March 13, 2017, 3:29am UTC](https://meta.discourse.org/t/creating-custom-notifications/58950/1 "2017-03-13T03:29:35Z")

</div>

Hi!

I want to create a custom notification when something happens in my plugin. I can see there is a custom notification type but I’m unsure about how to use it.

Something like:

```plaintext
data = {title: 'some custom event happened'}
Notification.create!(user_id: 1, notification_type: 14, data: data.to_json)

```

I can create them but they show ‘undefined’:

 ![](https://global.discourse-cdn.com/meta/original/3X/8/e/8e252612a01916c853baa272b18e87c714fa12b1.png)

Can someone please point me in the right direction? Any help much appreciated…

---

<div class="post-metadata">

### Author: ![joebuhlig](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/joebuhlig/32/193054_2.png) [@joebuhlig](https://meta.discourse.org/u/joebuhlig)
#### Post date: [March 13, 2017, 12:18pm UTC](https://meta.discourse.org/t/creating-custom-notifications/58950/2 "2017-03-13T12:18:43Z")

</div>

My first guess is that you haven’t defined the Notification type and throws an undefined error somewhere:

> <https://github.com/discourse/discourse/blob/main/app/models/notification.rb#L31>

Guess #2 is that the I18n text hasn’t been defined in `client.en.yml`.

Depending on what you want to share with the user, I’ve found it’s sometimes better to send a PM and then spell out what happened in more detail.

```ruby
PostCreator.create(
    Discourse.system_user,
    target_usernames: new_user.username,
    archetype: Archetype.private_message,
    subtype: TopicSubtype.system_message,
    title: I18n.t('translations.location'}),
    raw: I18n.t('translations.location'})
)

```

Edit: Just realized there’s a `custom` notification type (14) which you are using. So #1 is out.

---

<div class="post-metadata">

### Author: ![rimian](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rimian/32/120658_2.png) [@rimian](https://meta.discourse.org/u/rimian)
#### Post date: [March 13, 2017, 11:13pm UTC](https://meta.discourse.org/t/creating-custom-notifications/58950/3 "2017-03-13T23:13:31Z")

</div>

I was thinking a private message would be a good idea also. Thanks for that!
