Skip to content

Instantly share code, notes, and snippets.

@konstantinzolotarev
Last active April 19, 2019 10:13
Show Gist options
  • Save konstantinzolotarev/fcf953e4a5cf430a7bd92c8ec133e6af to your computer and use it in GitHub Desktop.
Save konstantinzolotarev/fcf953e4a5cf430a7bd92c8ec133e6af to your computer and use it in GitHub Desktop.
defmodule Encoder do
def encode(
username,
msg,
id \\ "mguFd-51",
to \\ "79040883-331c-4944-aca5-16e9351098c1@localhost"
) do
{:xmlel, "message",
[
{"xml:lang", "en"},
{"to", to},
{"id", id},
{"type", "chat"}
],
[
{:xmlel, "body", [], [xmlcdata: msg]},
{:xmlel, "username", [{"xmlns", "message:username"}], [xmlcdata: username]},
{:xmlel, "type", [{"xmlns", "message:type"}], [xmlcdata: "text"]}
]}
end
end
[id, username, to, msg] = System.argv()
msg =
Encoder.encode(username, msg, id, to)
|> :erlang.term_to_binary()
|> Base.encode16()
# Это просто распечатывает результат
"0x" <> msg
|> IO.puts()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment