Why don't you use the API to connect to the websocket and listen live to the messages?
https://api.mattermost.com/v4/#tag/WebSocket
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.