Packard_Goose

Packard_Goose

I’m trying to send a message using websockex but I’m getting an error when I try to send out my json string (I used Jason), what could I possibly be missing?

"{\"action\":\"subscribe\",\"options\":{\"accounts\":[\"nano_1qzfp3op48im348qdybmrheu9dogtopj1jyioguq9pyo5i7mkqgo4jaswp4a\"],\"all_local_accounts\":true},\"topic\":\"confirmation\"}"
** (ArgumentError) argument error
    :erlang.send(MitoNode.Client, {:"$websockex_cast", "{\"action\":\"subscribe\",\"options\":{\"accounts\":[\"nano_1qzfp3op48im348qdybmrheu9dogtopj1jyioguq9pyo5i7mkqgo4jaswp4a\"],\"all_local_accounts\":true},\"topic\":\"confirmation\"}"})
    (websockex) lib/websockex/utils.ex:57: WebSockex.Utils.send/2
    (websockex) lib/websockex.ex:398: WebSockex.cast/2

Showing Posts 1 to 5

NobbZ

NobbZ

:erlang.send/2 only fails when the first argument is an atom and this atom is not registered to a process name.

So you need to make sure, that there is actually a process with the name MitoNode.Client.

Or pass a pid that actually does exist.

But all of this is just guessing, as you have not even provided code, but just an error.

Packard_Goose

Packard_Goose OP

Sorry, my bad

Heres the construction of the message.

  def sub() do

    {:ok, message} = %{
    "action" => "subscribe",
    "topic" => "confirmation",
    "options" => %{
      "all_local_accounts" => true,
      "accounts" => [
        "nano_1qzfp3op48im348qdybmrheu9dogtopj1jyioguq9pyo5i7mkqgo4jaswp4a"
      ]
    }
  } |> Jason.encode

    IO.inspect(message)

    WebSockex.cast(__MODULE__, message)
  end

in my supervision tree I just have the child {MitoNode.Client, ["random WebSockex message"]} as per the example but I will try a pid too

NobbZ

NobbZ

That just delegates the start of the client to its start_link/1, IIRC.

But in that, do you actually name the started process?

Packard_Goose

Packard_Goose OP

Man you’re the best. Forgot the opts field in start_link, which of course had a name: field, tried subbing with the atom name I gave it and it works fine now. Thanks for the quick advice!

CamonZ

CamonZ

You can also use the pid of the WebSockex process and WebSockex.send_frame/2 to send the data. e.g.

{:ok, pid} = MyWebSockexWrapper.start_link()


msg = Jason.encode!(%{
    "action" => "subscribe",
    "topic" => "confirmation",
    "options" => %{
      "all_local_accounts" => true,
      "accounts" => [
        "nano_1qzfp3op48im348qdybmrheu9dogtopj1jyioguq9pyo5i7mkqgo4jaswp4a"
      ]
    })

WebSockex.send_frame(pid, {:text, msg})
— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
water
I’m aware of 2 such projects, are there others? git: GitHub - team-alembic/realworld: A fullstack Phoenix LiveView application with back...
New
itzmidinesh
Hi all, I’m working on a Phoenix project where I need to make external HTTP requests and I’m trying to choose between Req and HTTPoison....
New
peck
Hi everyone. My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
leoschweizer
Hi, we run different LLM models across a cluster, with each node loading a configurable subset. Model-specific queues let nodes consume ...
New
csmr
Hi all, I’m new here and would like to hear peoples views on my Elixir/Phoenix based game-engine! :smiley: Mutonex gamedesign was finish...
New
Stef-Verniers
Hello I’ve been coding in Elixir for almost two years now because of my current job where we implemented Elixir in our application. But ...
New

Other Trending Topics Top

dominicletz
Hey there, I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first. ...
New
raa-ziq
Hi everyone :waving_hand: I wanted to share something I’ve been building — NowBlind, a random chat app designed to help people discover ...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
OndrejValenta
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly) AI dream has many faces, but general...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews