View Source Glific.Messages (Glific v5.1.6)

The Messages context.

Link to this section Summary

Functions

Returns an %Ecto.Changeset{} for tracking message changes.

Returns an %Ecto.Changeset{} for tracking message media changes.

Delete all messages of a contact

Return the count of messages, using the same filter as list_messages

Return the count of messages, using the same filter as list_messages

Send a hsm template message to the specific contact.

Create and send message to all contacts of a group

Send a session template to the specific contact. This is typically used in automation

Record a message sent to a group in the message table. This message is actually not sent, but is used for display purposes in the group listings

Creates a message.

Creates a message media.

We need to simulate a few messages as we move to the system. This is a wrapper function to add those messages, which trigger specific actions within flows. e.g. include: Completed, Failure, Success etc

Deletes a message.

Deletes a message media.

Get Media type from a url. We will primary use it for when we receive the url from EEX call.

Gets a single message.

Gets a single message media.

Given a list of message ids builds a conversation list with most recent conversations at the beginning of the list

Returns the list of filtered messages.

Returns the list of message media.

Mark that the user has read all messages sent by a given contact

Create and insert a notification for this error when sending a message. Add as much detail, so we can reverse-engineer why the sending failed.

Check if the tag is present in message

Updates a message.

Link to this section Functions

Link to this function

change_message(message, attrs \\ %{})

View Source
@spec change_message(Glific.Messages.Message.t(), map()) :: Ecto.Changeset.t()

Returns an %Ecto.Changeset{} for tracking message changes.

examples

Examples

iex> change_message(message)
%Ecto.Changeset{data: %Message{}}
Link to this function

change_message_media(message_media, attrs \\ %{})

View Source
@spec change_message_media(Glific.Messages.MessageMedia.t(), map()) ::
  Ecto.Changeset.t()

Returns an %Ecto.Changeset{} for tracking message media changes.

examples

Examples

iex> change_message_media(message_media)
%Ecto.Changeset{data: %MessageMedia{}}
@spec clear_messages(Glific.Contacts.Contact.t()) :: :ok

Delete all messages of a contact

@spec count_messages(map()) :: integer()

Return the count of messages, using the same filter as list_messages

Link to this function

count_messages_media(args \\ %{})

View Source
@spec count_messages_media(map()) :: integer()

Return the count of messages, using the same filter as list_messages

Link to this function

create_and_send_hsm_message(attrs)

View Source
@spec create_and_send_hsm_message(map()) ::
  {:ok, Glific.Messages.Message.t()} | {:error, String.t()}

Send a hsm template message to the specific contact.

Link to this function

create_and_send_message_to_group(message_params, group, type)

View Source
@spec create_and_send_message_to_group(map(), Glific.Groups.Group.t(), atom()) ::
  {:ok, any()} | {:error, any()}

Create and send message to all contacts of a group

Link to this function

create_and_send_session_template(template_id, receiver_id)

View Source
@spec create_and_send_session_template(String.t(), integer()) ::
  {:ok, Glific.Messages.Message.t()}
@spec create_and_send_session_template(integer(), integer()) ::
  {:ok, Glific.Messages.Message.t()}
@spec create_and_send_session_template(
  Glific.Templates.SessionTemplate.t() | map(),
  map()
) ::
  {:ok, Glific.Messages.Message.t()}

Send a session template to the specific contact. This is typically used in automation

Link to this function

create_group_message(attrs)

View Source
@spec create_group_message(map()) ::
  {:ok, Glific.Messages.Message.t()} | {:error, Ecto.Changeset.t()}

Record a message sent to a group in the message table. This message is actually not sent, but is used for display purposes in the group listings

@spec create_message(map()) ::
  {:ok, Glific.Messages.Message.t()} | {:error, Ecto.Changeset.t()}

Creates a message.

examples

Examples

iex> create_message(%{field: value})
{:ok, %Message{}}

iex> create_message(%{field: bad_value})
{:error, %Ecto.Changeset{}}
Link to this function

create_message_media(attrs \\ %{})

View Source
@spec create_message_media(map()) ::
  {:ok, Glific.Messages.MessageMedia.t()} | {:error, Ecto.Changeset.t()}

Creates a message media.

examples

Examples

iex> create_message_media(%{field: value})
{:ok, %MessageMedia{}}

iex> create_message_media(%{field: bad_value})
{:error, %Ecto.Changeset{}}
Link to this function

create_temp_message(organization_id, body, attrs \\ [])

View Source
@spec create_temp_message(non_neg_integer(), any(), Keyword.t()) ::
  Glific.Messages.Message.t()

We need to simulate a few messages as we move to the system. This is a wrapper function to add those messages, which trigger specific actions within flows. e.g. include: Completed, Failure, Success etc

@spec delete_message(Glific.Messages.Message.t()) ::
  {:ok, Glific.Messages.Message.t()} | {:error, Ecto.Changeset.t()}

Deletes a message.

examples

Examples

iex> delete_message(message)
{:ok, %Message{}}

iex> delete_message(message)
{:error, %Ecto.Changeset{}}
Link to this function

delete_message_media(message_media)

View Source
@spec delete_message_media(Glific.Messages.MessageMedia.t()) ::
  {:ok, Glific.Messages.MessageMedia.t()} | {:error, Ecto.Changeset.t()}

Deletes a message media.

examples

Examples

iex> delete_message_media(message_media)
{:ok, %MessageMedia{}}

iex> delete_message_media(message_media)
{:error, %Ecto.Changeset{}}
Link to this function

get_media_type_from_url(url, opts \\ [])

View Source
@spec get_media_type_from_url(String.t(), Keyword.t()) :: tuple()

Get Media type from a url. We will primary use it for when we receive the url from EEX call.

@spec get_message!(integer()) :: Glific.Messages.Message.t()

Gets a single message.

Raises Ecto.NoResultsError if the Message does not exist.

examples

Examples

iex> get_message!(123)
%Message{}

iex> get_message!(456)
** (Ecto.NoResultsError)
@spec get_message_media!(integer()) :: Glific.Messages.MessageMedia.t()

Gets a single message media.

Raises Ecto.NoResultsError if the Message media does not exist.

examples

Examples

iex> get_message_media!(123)
%MessageMedia{}

iex> get_message_media!(456)
** (Ecto.NoResultsError)
Link to this function

list_conversations(args, count \\ false)

View Source
@spec list_conversations(map(), boolean()) ::
  [Glific.Conversations.Conversation.t()] | integer()

Given a list of message ids builds a conversation list with most recent conversations at the beginning of the list

@spec list_messages(map()) :: [Glific.Messages.Message.t()]

Returns the list of filtered messages.

examples

Examples

iex> list_messages(map())
[%Message{}, ...]
Link to this function

list_messages_media(args \\ %{})

View Source
@spec list_messages_media(map()) :: [Glific.Messages.MessageMedia.t()]

Returns the list of message media.

examples

Examples

iex> list_messages_media(map())
[%MessageMedia{}, ...]
Link to this function

mark_contact_messages_as_read(contact_id, organization_id)

View Source
@spec mark_contact_messages_as_read(non_neg_integer(), non_neg_integer()) :: nil

Mark that the user has read all messages sent by a given contact

Link to this function

notify(attrs, reason \\ "Cannot send the message to the contact.")

View Source
@spec notify(map(), String.t()) :: nil

Create and insert a notification for this error when sending a message. Add as much detail, so we can reverse-engineer why the sending failed.

Link to this function

tag_in_message?(message, tag_id)

View Source
@spec tag_in_message?(Glific.Messages.Message.t(), integer()) :: boolean()

Check if the tag is present in message

Link to this function

update_message(message, attrs)

View Source
@spec update_message(Glific.Messages.Message.t(), map()) ::
  {:ok, Glific.Messages.Message.t()} | {:error, Ecto.Changeset.t()}

Updates a message.

examples

Examples

iex> update_message(message, %{field: new_value})
{:ok, %Message{}}

iex> update_message(message, %{field: bad_value})
{:error, %Ecto.Changeset{}}
Link to this function

update_message_media(message_media, attrs)

View Source
@spec update_message_media(Glific.Messages.MessageMedia.t(), map()) ::
  {:ok, Glific.Messages.MessageMedia.t()} | {:error, Ecto.Changeset.t()}

Updates a message media.

examples

Examples

iex> update_message_media(message_media, %{field: new_value})
{:ok, %MessageMedia{}}

iex> update_message_media(message_media, %{field: bad_value})
{:error, %Ecto.Changeset{}}