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
Specs
can_send_message_to?(Glific.Contacts.Contact.t()) :: boolean()
Check if we can send a message to the contact
Specs
can_send_message_to?(Glific.Contacts.Contact.t(), boolean()) :: boolean()
Check if we can send a session message to the contact
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{}}
Specs
contact_location(Glific.Contacts.Contact.t()) :: {:ok, Glific.Contacts.Location.t()}
Get contact's current location
Specs
contact_opted_in(String.t(), non_neg_integer(), DateTime.t()) :: {:ok}
Update DB fields when contact opted in
Specs
contact_opted_out(String.t(), non_neg_integer(), DateTime.t()) :: {:ok}
Update DB fields when contact opted out
Specs
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{}}
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)
Specs
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
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
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{}}
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