- Published on
Deliver Messages with MTransmitter on Matrix
- Authors
- Name
- Williamo
- X
- @williamodev
Are you an Elements user looking to integrate a bot that supports encrypted channel messages without the hassle of complex setups? Well, you're in for a treat! Today, I'll be unveiling my secret bot that I've been using privately daily. The best part? It's now open for anyone to register and freely use in their channels. And don't worry, your privacy is respected. If this service gains popularity, I'll also work on making it easier for users to self-host the bot. So, let's explore how you can seamlessly enhance your Elements chats with this bot API!
For all of you who are new to Elements and Matrix, let's give you a brief introduction:
Matrix is an open, federated, and decentralized communication protocol that allows users to securely communicate, collaborate, and share information. It's like a universal messaging platform that lets you connect with people across different servers and networks seamlessly.
Elements, formerly known as Riot.im, is a popular communication platform built on top of the Matrix protocol. It serves as a powerful client that enables users to join chat rooms, make voice and video calls, share files, and enjoy end-to-end encrypted conversations.
Whether you're a tech enthusiast, a team collaborator, or someone looking for secure and efficient communication, Elements and Matrix have got you covered.
MTransmitter offers the convenience of sending messages in both HTML and markdown formats. This allows you to choose the best formatting option that suits your needs when delivering messages in Matrix channels. Enjoy the flexibility to customize your messages without any limitations. Whether you prefer plain text, rich HTML, or markdown, MTransmitter has the versatility you need.
Step 1: Register an Account on MTransmitter
Begin by registering an account on MTransmitter by sending a POST request with the following JSON payload.
Remember to include the server you are registered on in your username, or the bot will reject your invitations.
curl --request POST \
--url https://api.mtransmitter.com/v1/auth/register \
--header 'Content-Type: application/json' \
--data '{
"username": "@username:matrix.org",
"password": "replace_me",
"password_confirmation": "replace_me"
}'
{
"status": "success",
"data": {
"user": {
"username": "@username:matrix.org",
"verified": false,
"token": "1183a4e4aebf405a1a4ff9f5e4edfe026d171d07103ea41ko8a798534gd7n933"
}
}
}
Upon success, you'll receive a response with a token.
Step 2: Invite the Bot to Your Channel
Next, invite the bot with the name "mtrans:matrix.org" to your channel. Once the bot has joined your channel, you can verify its presence by sending a GET request. Include your token as a bearer token in the header, and you'll receive a response like this:
curl --request GET \
--url https://api.mtransmitter.com/v1/rooms \
--header 'Authorization: Bearer 1183a4e4aebf405a1a4ff9f5e4edfe026d171d07103ea41ko8a798534gd7n933' \
--header 'Content-type: application/json'
{
"status": "success",
"data": {
"rooms": [
{
"name": "!0i3jabudciu3h:xmr.se",
"token": "2f9e3fb4d88cfb7f92aff3cc703e614c3467a883k533bf2ac5e3d36c742e0587",
"bot_name": "mtrans",
"active": true,
"joined": true,
"joined_at": 1658242736
}
]
}
}
The token in the response will be used to send messages to that specific channel.
Step 3: Send Messages with MTransmitter API
You can now send messages to your channel either by posting JSON or including the message and token in a query.
Don't forget to include the token in the header, which you obtained from the room endpoint.
curl --request POST \
--url https://api.mtransmitter.com/v1/messages \
--header 'Authorization: Bearer 2f9e3fb4d88cfb7f92aff3cc703e614c3467a883k533bf2ac5e3d36c742e0587' \
--header 'Content-Type: application/json' \
--data '{
"message": "***Support for HTML & Markdown***<br>has been added<br>[Changelog](https://www.youtube.com/watch?v=O91DT1pR1ew)"
}'
{
"status": "success"
}
That's it! You're all set to use the MTransmitter API and send messages to your Matrix channels with ease. Happy messaging!
If you have any feature requests or want to share your thoughts, find me on X @williamodev. Your feedback is valuable and will shape MTransmitter's future.
PS: Token Troubles? No problem! Use this helpful endpoint (: Recover lost tokens with ease!
curl --request POST \
--url https://api.mtransmitter.com/v1/auth/token \
--header 'Content-Type: application/json' \
--data '{
"username": "@username:matrix.org",
"password": "replace_me"
}'