# Outgoing for direct message to user

**URL:** <https://forum.mattermost.com/t/outgoing-for-direct-message-to-user/3175>\
**Category:** Troubleshooting\
**Created:** [April 24, 2017, 12:57pm UTC](https://forum.mattermost.com/t/outgoing-for-direct-message-to-user/3175 "2017-04-24T12:57:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ruimoreira](https://avatars.discourse-cdn.com/v4/letter/r/7993a0/32.png) [@ruimoreira](https://forum.mattermost.com/u/ruimoreira)\
**Post date:** [April 24, 2017, 12:57pm UTC](https://forum.mattermost.com/t/outgoing-for-direct-message-to-user/3175/1 "2017-04-24T12:57:13Z")

</div>

Hi everyone, it’s my first post here, i’m glad to be with you guys.

So, the point is, i’m trying to find a way to trigger my nodeJS application every time a user receives a new message, i’d made something like this for a group chat last week using outgoing for a trigger word.  
I made a research and i didn’t find any post usefull so, i’m here to ask for your help.

Is it possible to user the outgoing method to this case or i need to make something like a fork that checks for a new message every second?

Thanks  
Rui

---

<div class="post-metadata">

**Author:** ![prixone](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/prixone/32/1184_2.png) [@prixone](https://forum.mattermost.com/u/prixone)\
**Post date:** [April 25, 2017, 2:19am UTC](https://forum.mattermost.com/t/outgoing-for-direct-message-to-user/3175/2 "2017-04-25T02:19:18Z")

</div>

Why don’t you use the API to connect to the websocket and listen live to the messages?

[https://api.mattermost.com/v4/#tag/commands%2Fpaths%2F~1commands~1execute%2Fpost](https://api.mattermost.com/v4/#tag/commands%2Fpaths%2F~1commands~1execute%2Fpost)

You could also use the API to post messages as needed or the incoming hook after you start listening to it to delivery your messages.

---

<div class="post-metadata">

**Author:** ![ruimoreira](https://avatars.discourse-cdn.com/v4/letter/r/7993a0/32.png) [@ruimoreira](https://forum.mattermost.com/u/ruimoreira)\
**Post date:** [July 3, 2017, 10:10am UTC](https://forum.mattermost.com/t/outgoing-for-direct-message-to-user/3175/3 "2017-07-03T10:10:24Z")

</div>

Thanks prixone for the reply.

So, i want to make a call to my api method, every time that my bot account receives a new private message.

Maybe i don’t understand how websockets work, but i’m affraid that doing filters on my api will increase the number of requests what can make my api very slow.

The perfect solution will be something like the outgoing webhooks but make the trigger be “new private message of user”.

Ty

---

<div class="post-metadata">

**Author:** ![prixone](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/prixone/32/1184_2.png) [@prixone](https://forum.mattermost.com/u/prixone)\
**Post date:** [July 3, 2017, 8:17pm UTC](https://forum.mattermost.com/t/outgoing-for-direct-message-to-user/3175/4 "2017-07-03T20:17:59Z")

</div>

You can use an outgoing for getting the messages and the API to execute the command, that would be a single call if you have already authenticated to the API for the duration of that token.

So initializing it you would login, get token, then you can call the execute command directly without authenticating every time.

[If that doesn’t fit your needs then I am afraid u will have to open a feature request so that Incoming Webhooks execute slash commands.](https://mattermost.uservoice.com/)

---

<div class="post-metadata">

**Author:** ![prixone](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/prixone/32/1184_2.png) [@prixone](https://forum.mattermost.com/u/prixone)\
**Post date:** [July 3, 2017, 10:57pm UTC](https://forum.mattermost.com/t/outgoing-for-direct-message-to-user/3175/5 "2017-07-03T22:57:30Z")

</div>

It was not supposed to link to websocket, but to the execute commands, my bad, for some reason my previous reply linked to the wrong item in the API documentation, right one is:

[https://api.mattermost.com/v4/#tag/commands%2Fpaths%2F~1commands~1execute%2Fpost](https://api.mattermost.com/v4/#tag/commands%2Fpaths%2F~1commands~1execute%2Fpost)
