# Use hooks for remove system messages from chat channel

**URL:** <https://forum.heroiclabs.com/t/use-hooks-for-remove-system-messages-from-chat-channel/4203>\
**Category:** Runtime Framework\
**Tags:** server-framework, golang\
**Created:** [August 8, 2023, 9:34am UTC](https://forum.heroiclabs.com/t/use-hooks-for-remove-system-messages-from-chat-channel/4203 "2023-08-08T09:34:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![DInjection](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/dinjection/32/1749_2.png) [@DInjection](https://forum.heroiclabs.com/u/DInjection)\
**Post date:** [August 8, 2023, 9:34am UTC](https://forum.heroiclabs.com/t/use-hooks-for-remove-system-messages-from-chat-channel/4203/1 "2023-08-08T09:34:36Z")

</div>

Hi  
For example, after GroupUsersPromote client recieved system message with empty Content and Code != 0.  
I need to intercept a system message received from a client.

I try to use this logic, but not success.

```auto
if err := initializer.RegisterBeforeRt("ChannelMessageSend", beforeChannelMessageSendHook); err != nil {
	return err
}

```

```auto
func beforeChannelMessageSendHook(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule,
	in *rtapi.Envelope) (*rtapi.Envelope, error) {

	message := in.GetChannelMessageSend()
	if message == nil {
		return in, nil
	}

	if len(message.Content) == 0 || message.Content == "{}" {
		return nil, runtime.NewError(fmt.Sprintf("Remove system message"), int(core.GRPC_ABORTED))
	}

	return in, nil
}

```

What am i doing wrong?

---

<div class="post-metadata">

**Author:** ![sesposito](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/sesposito/32/2594_2.png) [@sesposito](https://forum.heroiclabs.com/u/sesposito)\
**Post date:** [August 8, 2023, 10:47am UTC](https://forum.heroiclabs.com/t/use-hooks-for-remove-system-messages-from-chat-channel/4203/2 "2023-08-08T10:47:11Z")

</div>

Hello @DInjection,

The system message cannot be intercepted with the hook as `ChannelMessageSend` is only triggered when the function is invoked from a client, and not when a system message is sent.

If you’d like to not display the user promoted system message, you should ignore it from the client.

You can identify these messages through their [code](https://heroiclabs.com/docs/nakama/concepts/chat/#groups-1).

Best

---

<div class="post-metadata">

**Author:** ![DInjection](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/dinjection/32/1749_2.png) [@DInjection](https://forum.heroiclabs.com/u/DInjection)\
**Post date:** [August 8, 2023, 2:46pm UTC](https://forum.heroiclabs.com/t/use-hooks-for-remove-system-messages-from-chat-channel/4203/3 "2023-08-08T14:46:18Z")

</div>

Thanks for answer
