Skip to content

Instantly share code, notes, and snippets.

@rodrigues
Created May 30, 2021 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rodrigues/7c0dd1c8444b1acc05756beedc43a794 to your computer and use it in GitHub Desktop.
Save rodrigues/7c0dd1c8444b1acc05756beedc43a794 to your computer and use it in GitHub Desktop.
## 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