Glific v0.3.1 Glific.Contacts View Source

The Contacts context.

Link to this section Summary

Functions

Check if we can send a message to the contact

Check if we can send a session message to the contact

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

Get contact's current location

Update DB fields when contact opted in

Update DB fields when contact opted out

Return the count of contacts, using the same filter as list_contacts

Creates a contact.

Creates a location.

Deletes a contact.

Gets a single contact.

Check if this contact id is a new conatct

Returns the list of contacts.

Set session status for opted in and opted out contacts

Updates a contact.

Invoked from cron jobs to mass update the status of contacts belonging to a specific organization

Gets or Creates a Contact based on the unique indexes in the table. If there is a match it returns the existing contact, else it creates a new one

Link to this section Functions

Link to this function

can_send_message_to?(contact)

View Source

Specs

can_send_message_to?(Glific.Contacts.Contact.t()) :: boolean()

Check if we can send a message to the contact

Link to this function

can_send_message_to?(contact, is_hsm)

View Source

Specs

can_send_message_to?(Glific.Contacts.Contact.t(), boolean()) :: boolean()

Check if we can send a session message to the contact

Link to this function

change_contact(contact, attrs \\ %{})

View Source

Specs

change_contact(Glific.Contacts.Contact.t(), map()) :: Ecto.Changeset.t()

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

Examples

iex> change_contact(contact)
%Ecto.Changeset{data: %Contact{}}
Link to this function

contact_location(contact)

View Source

Specs

contact_location(Glific.Contacts.Contact.t()) ::
  {:ok, Glific.Contacts.Location.t()}

Get contact's current location

Link to this function

contact_opted_in(phone, organization_id, utc_time)

View Source

Specs

contact_opted_in(String.t(), non_neg_integer(), DateTime.t()) :: {:ok}

Update DB fields when contact opted in

Link to this function

contact_opted_out(phone, organization_id, utc_time)

View Source

Specs

contact_opted_out(String.t(), non_neg_integer(), DateTime.t()) :: {:ok}

Update DB fields when contact opted out

Specs

count_contacts(map()) :: integer()

Return the count of contacts, using the same filter as list_contacts

Specs

create_contact(map()) ::
  {:ok, Glific.Contacts.Contact.t()} | {:error, Ecto.Changeset.t()}

Creates a contact.

Examples

iex> create_contact(%{field: value})
{:ok, %Contact{}}

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

create_location(attrs \\ %{})

View Source

Specs

create_location(map()) ::
  {:ok, Glific.Contacts.Location.t()} | {:error, Ecto.Changeset.t()}

Creates a location.

Examples

iex> Glific.Contacts.create_location(%{name: value})
{:ok, %Glific.Contacts.Location{}}

iex> Glific.Contacts.create_location(%{bad_field: bad_value})
{:error, %Ecto.Changeset{}}

Specs

delete_contact(Glific.Contacts.Contact.t()) ::
  {:ok, Glific.Contacts.Contact.t()} | {:error, Ecto.Changeset.t()}

Deletes a contact.

Examples

iex> delete_contact(contact)
{:ok, %Contact{}}

iex> delete_contact(contact)
{:error, %Ecto.Changeset{}}

Specs

get_contact!(integer()) :: Glific.Contacts.Contact.t()

Gets a single contact.

Raises Ecto.NoResultsError if the Contact does not exist.

Examples

iex> get_contact!(123)
%Contact{}

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

is_new_contact(contact_id)

View Source

Specs

is_new_contact(integer()) :: boolean()

Check if this contact id is a new conatct

Specs

list_contacts(map()) :: [Glific.Contacts.Contact.t()]

Returns the list of contacts.

Examples

iex> list_contacts()
[%Contact{}, ...]

Get the list of contacts filtered by various search options Include contacts only if within list of groups Include contacts only if have list of tags

Link to this function

set_session_status(contact, status)

View Source

Specs

set_session_status(Glific.Contacts.Contact.t() | [non_neg_integer()], atom()) ::
  {:ok, Glific.Contacts.Contact.t()} | {:error, Ecto.Changeset.t()} | :ok

Set session status for opted in and opted out contacts

Link to this function

update_contact(contact, attrs)

View Source

Specs

update_contact(Glific.Contacts.Contact.t(), map()) ::
  {:ok, Glific.Contacts.Contact.t()} | {:error, Ecto.Changeset.t()}

Updates a contact.

Examples

iex> update_contact(contact, %{field: new_value})
{:ok, %Contact{}}

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

update_contact_status(organization_id, args)

View Source

Specs

update_contact_status(non_neg_integer(), map()) :: :ok

Invoked from cron jobs to mass update the status of contacts belonging to a specific organization

In this case, if we can, we might want to do it across the entire DB since the update is across all organizations. The main issue might be the row level security of postgres and how it ties in. For now, lets stick to per organization

Specs

upsert(map()) :: {:ok, Glific.Contacts.Contact.t()}

Gets or Creates a Contact based on the unique indexes in the table. If there is a match it returns the existing contact, else it creates a new one