necromorph23

necromorph23

Hello Everyone,

I am trying to create a Chat app like whatsapp and i have bascially read every other discussion on the forum regarding this topic and decided to use ejabberd (because i want to store messages when the reciever is offline , and security was also an issue.). I have also watched few implementations of Ejabberd in Phoenix Application.

Though i still have few doubts, i am already halfway through my application (its an application with many features chat is just a part of it) and i have my own Auth system in application which is working, my question is do i still need to use something like ejabberd.auth() and get JID from it to initiate my Chat stuff and from where can anyone give me some resources to understand the docs.

There is a lot of stuff and it’s quite overwhelming, also if anyone can give me some github link or anything if this stuff has already been implemented by someone else so that i can have a look.

Any help would be appreciated. Thanks for listening.

Showing Posts 1 to 8

derek-zhou

derek-zhou

It seems like you have a lot to share; why not share whatever you have first?

necromorph23

necromorph23 OP

Alright let’s start with the simple stuff

  1. My application is what you could say is like Reddit + WA. I am almost done with the reddit part and decided to look into how am i going to implement the WA one.

  2. Initially i thought i could just work with Websockets but they don’t provide all the services i needed. Like media transfers and how am i going to store messages for offline users and then deliver it.

  3. Thats why i researched more and decided to go with Ejabberd.

The difficult stuff.

  1. I have seen little bit of documentation and few implementation of Ejabberd in elixir but still not able to understand how am i going to implement one-to-one chat and multi user chat and also Video/Voice calls.

  2. Researched a little bit more then i came to know about JID (Jabber ID) and then i realized (i might be wrong here) that Ejabberd basically calls functions like
    ejabberdctl send_message chat 192.168.33.50 user1@192.168.33.50 “subject” “message from server”

and i guess here “user1@192.168.33.50” is acting like the JID.

The confusion part:-

  1. I already have implemented basic Auth system with email and password but for chat functionality i think i need to generate somekind of JID as well i guess?

  2. Even after i generate JID lets say how do i implement these one-to-one and multi user chat in my application because Ejabberd docs are some what confusing to me.

This basically sums up my problem.
Now few additional questions that i have if anyone can answer them
Q1) Should i use MNESIA or Postgresql as Database? (For my reddit part i am using PostgreSQL)

Q2) Do we generate JID again and again when user connects to the internet or it is generated only once when user first registers?

derek-zhou

derek-zhou

You ask a lot of questions like “Should I …” These questions are generally unanswerable because we do not know your situation as good as you. If you can re-phrase your question into non-subjective and isolated question you can greatly increase your chance of getting help, and the helpers and on-lookers, etc can benefit from the discussion as well.

JeyHey

JeyHey

Q1: If you store the messages only until they are delivered and then delete them - giving the client the responsibility to store them (like WA does it) then I would say mnesia is good choice. If you want to store them on the server potentially indefinitely and make the client query them each time (like FB) then I would say Postgres is a better choice. But it is difficult to say and depends on a lot of factors.

Q2: A JID needs to be generated only once per user. But you don’t even need to as you can reuse your existing auth. All you need to do is to store it in a way Ejabberd can access it. Then, with a minimal amount of logic, you can make your client just construct the JID for authentication with Ejabberd und Ejabberd check the credentials. A JID has the following form: [username]@[serverdomain]/[resource]. Make Ejabberd aware of the domain and set a random constant resource.

At the end of the day, Ejabberd implements the XMPP protocol. So it would certainly not be a bad idea to take a look at the following book if you haven’t already: https://www.amazon.com/XMPP-Definitive-Real-Time-Applications-Technologies/dp/059652126X

necromorph23

necromorph23 OP

Thanks for all the insights. Though i am facing a new problem now. I have been trying to install ejabberd in my phoenix app i am getting this error.

I have tried to downgrade ejabberd but it does not seem to be working. This is my mix.exs

defmodule ChatTest.MixProject do
  use Mix.Project

  def project do
    [
      app: :chat_test,
      version: "0.1.0",
      elixir: "~> 1.13.4",
      elixirc_paths: elixirc_paths(Mix.env()),
      compilers: [:gettext] ++ Mix.compilers(),
      start_permanent: Mix.env() == :prod,
      aliases: aliases(),
      deps: deps()
    ]
  end

  # Configuration for the OTP application.
  #
  # Type `mix help compile.app` for more information.
  def application do
    [
      mod: {ChatTest.Application, []},
      extra_applications: [:logger, :runtime_tools, :ejabberd]
    ]
  end

  # Specifies which paths to compile per environment.
  defp elixirc_paths(:test), do: ["lib", "test/support"]
  defp elixirc_paths(_), do: ["lib"]

  # Specifies your project dependencies.
  #
  # Type `mix help deps` for examples and options.
  defp deps do
    [
      {:phoenix, "~> 1.6.13"},
      {:phoenix_ecto, "~> 4.4"},
      {:ecto_sql, "~> 3.6"},
      {:postgrex, ">= 0.0.0"},
      {:phoenix_live_dashboard, "~> 0.6"},
      {:swoosh, "~> 1.3"},
      {:telemetry_metrics, "~> 0.6"},
      {:telemetry_poller, "~> 1.0"},
      {:gettext, "~> 0.18"},
      {:jason, "~> 1.2"},
      {:plug_cowboy, "~> 2.5"},
      {:absinthe, "~> 1.7"},
      {:absinthe_plug, "~> 1.5"},      
      {:ejabberd, "~> 22.5", github: "processone/ejabberd"}
    ]
  end

  # Aliases are shortcuts or tasks specific to the current project.
  # For example, to install project dependencies and perform other setup tasks, run:
  #
  #     $ mix setup
  #
  # See the documentation for `Mix` for more info on aliases.
  defp aliases do
    [
      setup: ["deps.get", "ecto.setup"],
      "ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
      "ecto.reset": ["ecto.drop", "ecto.setup"],
      test: ["ecto.create --quiet", "ecto.migrate --quiet", "test"]
    ]
  end
end

Do you have any idea how can i solve this?

Hermanverschooten

Hermanverschooten

Try to remove the version number.

necromorph23

necromorph23 OP

Update: The app has compiled but when i start my phoenix server i am getting this error.

When i commented mod_irc in ejabberd.yml. I got this error.

Just for the context i was referring to this guide
Embedding Ejabberd in your Phoenix App

necromorph23

necromorph23 OP

New updated. I just had to make few changes to ejabberd.yml it seems to be working now. my phoenix app is also running.

— All posts loaded —

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
ChrisAmelia
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication): toke...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews