Created
May 30, 2021 16:50
-
-
Save rodrigues/7c0dd1c8444b1acc05756beedc43a794 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 1. connecting to MongooseIM from Elixir with escalus hex package | |
user_spec = [ | |
username: @username, | |
password: @password | |
] | |
config = [] | |
config = :escalus_cleaner.start(config) | |
# this connects to MIM and returns a client you | |
# will need to send and receive messages | |
{:ok, client} = :escalus_client.start(config, user_spec, @device_name) | |
roster = :escalus_stanza.roster_get() | |
:ok = :escalus_client.send(client, roster) | |
presence = :escalus_stanza.presence("available") | |
:ok = :escalus_client.send(client, presence) | |
# now you're connected and online. | |
## 2. receiving a message from MongooseIM | |
# it blocks and returns when there's a new message to handle | |
stanza = :escalus.wait_for_stanza(client, @listen_timeout_ms) | |
## 3. sending a message to MongooseIM | |
destination = "usr@host" | |
message = "test" | |
stanza = :escalus_stanza.chat_to(destination, message) | |
:ok = :escalus.send(client, stanza) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment