A message to push informations to a channel.
Initialize a message with a topic and an event.
init "room:lobby" "new_msg"
Attach a payload to a message
payload =
Json.Encode.object
[ ( "msg"
, Json.Encode.string "Hello Phoenix"
)
]
init "room:lobby" "new_msg"
|> withPayload payload
Callback if the server replies with an "ok" status.
type Msg = MessageArrived | ...
payload =
Json.Encode.object
[ ( "msg"
, Json.Encode.string "Hello Phoenix"
)
]
init "room:lobby" "new_msg"
|> withPayload payload
|> onOk (\_ -> MessageArrived)
Callback if the server replies with an "error" status.
type Msg = MessageFailed Value | ...
payload =
Json.Encode.object
[ ( "msg"
, Json.Encode.string "Hello Phoenix"
)
]
init "room:lobby" "new_msg"
|> withPayload payload
|> onError MessageFailed
The message abstraction
Note: You should use the helper functions to construct a Push message.