gcentauri / tuvix

A Matrix client in Erlang
GNU General Public License v3.0
0 stars 0 forks source link

Add: Matrix module post message to room #1

Closed gcentauri closed 5 years ago

gcentauri commented 5 years ago

We need a function for the Matrix api to post messages into a given room or rooms

https://matrix.org/docs/spec/client_server/latest#id305

PUT /_matrix/client/r0/rooms/%21636q39766251%3Aexample.com/send/m.room.message/35 HTTP/1.1
Content-Type: application/json

{
  "msgtype": "m.text",
  "body": "hello"
}

responds with the event id

ghost commented 5 years ago

For generating transaction id's I was thinking of just doing this:

dumb_id(Token) ->
    RandString = lists:flatten(io_lib:format("~p", [random:uniform()])),
    Hashed = crypto:hash(Token ++ RandString),
    base64:encode_to_string(Hashed).

in the matrix module.

The above may not be a good long term solution. We may want to have the client keep those ids for some reason. I'm just assuming the bot is fine with throwing them away.

gcentauri commented 5 years ago

that link i posted didn't go where i expected it to. I don't really see a problem with your dumb_id, though it is hard to tell from the example what it is intended to be. The only reason I can think of for the client to hang on to it is if we want it to keep trying to post a message if we don't get some acknowledgement back from the server. 🤷‍♀