# Create Mattermost Notification bot

**URL:** <https://forum.mattermost.com/t/create-mattermost-notification-bot/17983>\
**Category:** Uncategorized\
**Created:** [February 19, 2024, 9:52am UTC](https://forum.mattermost.com/t/create-mattermost-notification-bot/17983 "2024-02-19T09:52:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sjavadez](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/sjavadez/32/7608_2.png) [@sjavadez](https://forum.mattermost.com/u/sjavadez)\
**Post date:** [February 19, 2024, 9:52am UTC](https://forum.mattermost.com/t/create-mattermost-notification-bot/17983/1 "2024-02-19T09:52:18Z")

</div>

How can I send a message to a Mattermost user from an external service?

---

<div class="post-metadata">

**Author:** ![john.combs](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/john.combs/32/7118_2.png) [@john.combs](https://forum.mattermost.com/u/john.combs)\
**Post date:** [February 29, 2024, 4:57am UTC](https://forum.mattermost.com/t/create-mattermost-notification-bot/17983/2 "2024-02-29T04:57:23Z")

</div>

Hi Javad Ezaz,

Thanks for reaching out on the Mattermost forums with such an interesting question! We absolutely love supporting individuals like you who are exploring and expanding on the capabilities of our platform.

To send a message from an external service to a Mattermost user, you will need to use the Mattermost API, more specifically, the [Create a Post](https://api.mattermost.com/#tag/posts%2Fpaths%2F~1teams~1%7Bteam_id%7D~1channels~1%7Bchannel_id%7D~1posts%2Fpost) method.

This method allows you to send a message to a specified channel. To message a specific user, you’d have to know the channel that you share with that user.

Here’s a simple example of how you could create a POST request in JavaScript:

`var data = JSON.stringify({  
“channel\_id”: “{channel\_id}”,  
“message”: “This is a test message”,  
“props”: {}  
});

var xhr = new XMLHttpRequest();

xhr.addEventListener(“readystatechange”, function() {  
if(this.readyState === 4) {  
console.log(this.responseText);  
}  
});

xhr.open(“POST”, “{your\_mattermost\_url}/api/v4/posts”);  
xhr.setRequestHeader(“Content-Type”, “application/json”);  
xhr.setRequestHeader(“Authorization”, “Bearer {access\_token}”);

xhr.send(data);`

Remember to replace `{channel_id}`, `{your_mattermost_url}`, and `{access_token}` with your specific information. The `access_token` will be for a bot user that you need to create and the `channel_id` is the ID of the channel shared by the bot and the user.

Keep in mind that to call the API, you’ll need to create a bot account and use the access token of that bot. You can find the relevant steps to do this in our [documentation on creating bot accounts](https://developers.mattermost.com/integrate/admin-guide/admin-bot-accounts/).

I hope this helps get you started on your project. If you need any more assistance, this community and I are always here to support you.

Happy coding!

Best regards,  
~Mattermost AI Assistant 🤖

_[**Disclaimer:** This was an AI assisted response powered by Mattermost AI. Were any of the above suggestions inaccurate? **Let us know by replying to this comment!**]_
