clj-symphony.message

Operations related to MessageMLv2 messages, which combine one or more of:

  1. a human-readable message (formatted using a subset of HTML called ‘PresentationML’)
  2. a machine readable JSON blob called the ‘entity data’
  3. an attachment

See:

deregister-listener!

(deregister-listener! c l)

Deregisters a previously-registered message listener. Once deregistered, a listener should be discarded (they cannot be reused). Returns true if a valid message listener was deregistered, false otherwise.

entity-ids

(entity-ids text)

Returns an ordered sequence of all entity ids found in the given PresentationML.

escape

(escape s)

Escapes the given string as content in a MessageMLv2 message.

mentions

multimethod

(mentions m)

Returns the list of user ids mentioned in the message (or nil if there aren’t any). Note that due to a bug in Symphony, @mentions of cross-pod users that the author of the message isn’t connected to will be missing from the result.

msgobj->map

(msgobj->map m)

Converts a org.symphonyoss.symphony.clients.model.SymMessage object into a map with these keys:

Key Description
:message-id The id of the message.
:timestamp The timestamp of the message.
:stream-id The stream id of the stream the message was sent to.
:user-id The user id of the user who sent the message.
:type The ‘type’ of the message. (seems to be unused??)
:text The PresentationML ‘text’ of the message.
:attachment The attachment for the message (if any).
:entity-data The parsed JSON ‘entity data’ for the message as a map (if any).

register-listener!

(register-listener! c f)

Registers f, a function with 1 parameter, as a message listener (callback), and returns a handle to that listener so that it can be deregistered later on, if needed. Listeners registered in this manner are not scoped to any particular stream - they will be sent all messages from all streams that the authenticated connection user is a participant in.

The argument passed to f is a map generated by msgobj->map.

The value returned by f (if any) is ignored.

sanitise-tag

(sanitise-tag s)

Sanitises the given string for use in a Symphony hashtag or cashtag.

sanitize-tag

English (simplified) version of sanitise-tag. See that fn for details.

send-message!

(send-message! c s m)(send-message! c s m ed)(send-message! c s m ed a)

Sends a message to the stream s (which can be anything supported by clj-symphony.stream/stream-id).

  • m is a String containing MessageMLv2
  • ed is a map or a JSON String containing entity data (a map will be converted to a String)
  • a is an attachment (something compatible with clojure.java.io/file)

to-plain-text

(to-plain-text text)

Converts a MessageML message to plain text, by stripping most tags, converting <p> and <br/> tags into newlines, and unescaping HTML entities into their Unicode equivalents.

tokens

(tokens m)

Returns the tokens (words) in the given MessageML message, in all lower case. Splits on whitespace and punctuation (via the Java regex pattern [\p{Punct}\s]+). Note that message content that contains whitespace within a single tag will also be split - this is especially noticable for @mentions containing a person’s first and last names.