Class ContactsResource

Hierarchy

  • Resource
    • ContactsResource

Constructors

Methods

  • Da de alta un contacto, o devuelve el que ya había.

    Hace falta al menos un identificador (error 1601): un contacto sin canal es un contacto al que nadie puede escribir. Y si ya existe uno con el primer canal y el mismo external_identifier, vuelve ÉSE tal cual, sin aplicar nada de lo que se mandó.

    const contact = await pv.contacts.create(orgId, {
    name: "Marta",
    social_identifiers: [{ social_network: "whatsapp", external_identifier: "34600111222" }],
    });

    Parameters

    • idOrganization: string
    • body: {
          extra_data?: {
              address?: string;
              boolean_property?: boolean;
              boolean_property2?: boolean;
              building?: string | number;
              city?: string;
              coords?: number[];
              country?: string;
              country_code?: string;
              door?: string | number;
              floor?: string | number;
              number?: string | number;
              number_property?: number;
              number_property2?: number;
              place_id?: string;
              state?: string;
              string_property?: string;
              string_property2?: string;
              zip_code?: string | number;
          };
          name?: string;
          profile_image?: string;
          social_identifiers: {
              _id?: string;
              external_identifier?: string;
              social_network: | "facebook"
              | "instagram"
              | "linkedin"
              | "tiktok"
              | "twitter"
              | "whatsapp"
              | "youtube"
              | "google_business"
              | "bluesky"
              | "discord"
              | "email";
          }[];
      }
    • options: RequestOptions = {}

    Returns Promise<
        {
            _id: string;
            creation_date: string;
            creator_keycloak_identifier?: string;
            extra_data?: {
                address?: string;
                boolean_property?: boolean;
                boolean_property2?: boolean;
                building?: string
                | number;
                city?: string;
                coords?: number[];
                country?: string;
                country_code?: string;
                door?: string | number;
                floor?: string | number;
                number?: string | number;
                number_property?: number;
                number_property2?: number;
                place_id?: string;
                state?: string;
                string_property?: string;
                string_property2?: string;
                zip_code?: string | number;
            };
            id_organization: string;
            last_contact_update: string;
            name?: string;
            profile_image?: string;
            social_identifiers: {
                _id: string;
                external_identifier?: string;
                last_send_date?: string;
                social_network: | "facebook"
                | "instagram"
                | "linkedin"
                | "tiktok"
                | "twitter"
                | "whatsapp"
                | "youtube"
                | "google_business"
                | "bluesky"
                | "discord"
                | "email";
            }[];
        },
    >

  • Un contacto.

    Parameters

    Returns Promise<
        {
            _id: string;
            creation_date: string;
            creator_keycloak_identifier?: string;
            extra_data?: {
                address?: string;
                boolean_property?: boolean;
                boolean_property2?: boolean;
                building?: string
                | number;
                city?: string;
                coords?: number[];
                country?: string;
                country_code?: string;
                door?: string | number;
                floor?: string | number;
                number?: string | number;
                number_property?: number;
                number_property2?: number;
                place_id?: string;
                state?: string;
                string_property?: string;
                string_property2?: string;
                zip_code?: string | number;
            };
            id_organization: string;
            last_contact_update: string;
            name?: string;
            profile_image?: string;
            social_identifiers: {
                _id: string;
                external_identifier?: string;
                last_send_date?: string;
                social_network: | "facebook"
                | "instagram"
                | "linkedin"
                | "tiktok"
                | "twitter"
                | "whatsapp"
                | "youtube"
                | "google_business"
                | "bluesky"
                | "discord"
                | "email";
            }[];
        },
    >

  • La agenda, encadenando páginas.

    Parameters

    Returns AsyncGenerator<
        {
            _id: string;
            creation_date: string;
            creator_keycloak_identifier?: string;
            extra_data?: {
                address?: string;
                boolean_property?: boolean;
                boolean_property2?: boolean;
                building?: string
                | number;
                city?: string;
                coords?: number[];
                country?: string;
                country_code?: string;
                door?: string | number;
                floor?: string | number;
                number?: string | number;
                number_property?: number;
                number_property2?: number;
                place_id?: string;
                state?: string;
                string_property?: string;
                string_property2?: string;
                zip_code?: string | number;
            };
            id_organization: string;
            last_contact_update: string;
            name?: string;
            profile_image?: string;
            social_identifiers: {
                _id: string;
                external_identifier?: string;
                last_send_date?: string;
                social_network: | "facebook"
                | "instagram"
                | "linkedin"
                | "tiktok"
                | "twitter"
                | "whatsapp"
                | "youtube"
                | "google_business"
                | "bluesky"
                | "discord"
                | "email";
            }[];
        },
    >

  • La agenda de la organización, de la más reciente a la más antigua.

    No hay filtro por red que funcione. El servidor acepta un social_network que compara el array social_identifiers entero contra el nombre de la red, así que no casa nunca y la lista vuelve vacía; por eso este método no lo expone. Filtra sobre social_identifiers en memoria.

    Parameters

    Returns Promise<
        Paginated<
            {
                _id: string;
                creation_date: string;
                creator_keycloak_identifier?: string;
                extra_data?: {
                    address?: string;
                    boolean_property?: boolean;
                    boolean_property2?: boolean;
                    building?: string
                    | number;
                    city?: string;
                    coords?: number[];
                    country?: string;
                    country_code?: string;
                    door?: string | number;
                    floor?: string | number;
                    number?: string | number;
                    number_property?: number;
                    number_property2?: number;
                    place_id?: string;
                    state?: string;
                    string_property?: string;
                    string_property2?: string;
                    zip_code?: string | number;
                };
                id_organization: string;
                last_contact_update: string;
                name?: string;
                profile_image?: string;
                social_identifiers: {
                    _id: string;
                    external_identifier?: string;
                    last_send_date?: string;
                    social_network: | "facebook"
                    | "instagram"
                    | "linkedin"
                    | "tiktok"
                    | "twitter"
                    | "whatsapp"
                    | "youtube"
                    | "google_business"
                    | "bluesky"
                    | "discord"
                    | "email";
                }[];
            },
        >,
    >

  • Como update, pero leyendo el contacto antes para no perder su extra_data.

    Son DOS peticiones y no es gratis; existe porque el borrado silencioso de extra_data es el fallo que se comete una vez y se descubre semanas después. Lo que se pase en extra_data se funde sobre lo que había, campo a campo; para vaciarlo de verdad, update() con extra_data: {}.

    Parameters

    • idOrganization: string
    • idContact: string
    • body: {
          extra_data?: {
              address?: string;
              boolean_property?: boolean;
              boolean_property2?: boolean;
              building?: string | number;
              city?: string;
              coords?: number[];
              country?: string;
              country_code?: string;
              door?: string | number;
              floor?: string | number;
              number?: string | number;
              number_property?: number;
              number_property2?: number;
              place_id?: string;
              state?: string;
              string_property?: string;
              string_property2?: string;
              zip_code?: string | number;
          };
          name?: string;
          profile_image?: string;
          social_identifiers?: {
              _id?: string;
              external_identifier?: string;
              social_network: | "facebook"
              | "instagram"
              | "linkedin"
              | "tiktok"
              | "twitter"
              | "whatsapp"
              | "youtube"
              | "google_business"
              | "bluesky"
              | "discord"
              | "email";
          }[];
      }
      • Optionalextra_data?: {
            address?: string;
            boolean_property?: boolean;
            boolean_property2?: boolean;
            building?: string | number;
            city?: string;
            coords?: number[];
            country?: string;
            country_code?: string;
            door?: string | number;
            floor?: string | number;
            number?: string | number;
            number_property?: number;
            number_property2?: number;
            place_id?: string;
            state?: string;
            string_property?: string;
            string_property2?: string;
            zip_code?: string | number;
        }

        Written as sent. Omitting it erases the contact's custom fields.

        • Optionaladdress?: string
        • Optionalboolean_property?: boolean
        • Optionalboolean_property2?: boolean
        • Optionalbuilding?: string | number
        • Optionalcity?: string
        • Optionalcoords?: number[]

          Longitude and latitude, in that order.

        • Optionalcountry?: string
        • Optionalcountry_code?: string
        • Optionaldoor?: string | number
        • Optionalfloor?: string | number
        • Optionalnumber?: string | number
        • Optionalnumber_property?: number
        • Optionalnumber_property2?: number
        • Optionalplace_id?: string
        • Optionalstate?: string
        • Optionalstring_property?: string
        • Optionalstring_property2?: string
        • Optionalzip_code?: string | number
      • Optionalname?: string
      • Optionalprofile_image?: string
      • Optionalsocial_identifiers?: {
            _id?: string;
            external_identifier?: string;
            social_network:
                | "facebook"
                | "instagram"
                | "linkedin"
                | "tiktok"
                | "twitter"
                | "whatsapp"
                | "youtube"
                | "google_business"
                | "bluesky"
                | "discord"
                | "email";
        }[]

        Replaces the whole list, it does not merge into it. Omit it to keep the current one.

    • options: RequestOptions = {}

    Returns Promise<void>

  • Borra el contacto y todos sus mensajes.

    Parameters

    Returns Promise<void>

  • Borra TODOS los contactos de la organización y TODOS sus mensajes.

    No pide confirmación y no hay vuelta atrás. Está aquí porque la API lo tiene, no porque sea una operación de todos los días.

    Parameters

    Returns Promise<void>

  • Cambia un contacto. No devuelve el contacto: la API contesta {success: true}, así que este método no devuelve nada y hay que volver a pedirlo si se quiere ver el resultado.

    CUIDADO CON extra_data: es el único campo que NO se conserva al omitirlo. El servidor lo escribe con lo que traiga el cuerpo, así que un update() sin extra_data deja el contacto sin ninguno de sus campos propios. name, profile_image y social_identifiers sí se respetan cuando no viajan. Para no tener que acordarse, merge.

    social_identifiers REEMPLAZA la lista entera, no se funde con ella.

    Parameters

    • idOrganization: string
    • idContact: string
    • body: {
          extra_data?: {
              address?: string;
              boolean_property?: boolean;
              boolean_property2?: boolean;
              building?: string | number;
              city?: string;
              coords?: number[];
              country?: string;
              country_code?: string;
              door?: string | number;
              floor?: string | number;
              number?: string | number;
              number_property?: number;
              number_property2?: number;
              place_id?: string;
              state?: string;
              string_property?: string;
              string_property2?: string;
              zip_code?: string | number;
          };
          name?: string;
          profile_image?: string;
          social_identifiers?: {
              _id?: string;
              external_identifier?: string;
              social_network: | "facebook"
              | "instagram"
              | "linkedin"
              | "tiktok"
              | "twitter"
              | "whatsapp"
              | "youtube"
              | "google_business"
              | "bluesky"
              | "discord"
              | "email";
          }[];
      }
      • Optionalextra_data?: {
            address?: string;
            boolean_property?: boolean;
            boolean_property2?: boolean;
            building?: string | number;
            city?: string;
            coords?: number[];
            country?: string;
            country_code?: string;
            door?: string | number;
            floor?: string | number;
            number?: string | number;
            number_property?: number;
            number_property2?: number;
            place_id?: string;
            state?: string;
            string_property?: string;
            string_property2?: string;
            zip_code?: string | number;
        }

        Written as sent. Omitting it erases the contact's custom fields.

        • Optionaladdress?: string
        • Optionalboolean_property?: boolean
        • Optionalboolean_property2?: boolean
        • Optionalbuilding?: string | number
        • Optionalcity?: string
        • Optionalcoords?: number[]

          Longitude and latitude, in that order.

        • Optionalcountry?: string
        • Optionalcountry_code?: string
        • Optionaldoor?: string | number
        • Optionalfloor?: string | number
        • Optionalnumber?: string | number
        • Optionalnumber_property?: number
        • Optionalnumber_property2?: number
        • Optionalplace_id?: string
        • Optionalstate?: string
        • Optionalstring_property?: string
        • Optionalstring_property2?: string
        • Optionalzip_code?: string | number
      • Optionalname?: string
      • Optionalprofile_image?: string
      • Optionalsocial_identifiers?: {
            _id?: string;
            external_identifier?: string;
            social_network:
                | "facebook"
                | "instagram"
                | "linkedin"
                | "tiktok"
                | "twitter"
                | "whatsapp"
                | "youtube"
                | "google_business"
                | "bluesky"
                | "discord"
                | "email";
        }[]

        Replaces the whole list, it does not merge into it. Omit it to keep the current one.

    • options: RequestOptions = {}

    Returns Promise<void>