Google Messages

Learn how to link a Google Messages account, list chats, and send your first message with Unipile.

Prerequisites

Before we start, you need to:

  1. Signup to Unipile.
  2. Create an Application in the dashboard.
  3. Create an API Key from the dashboard.
  4. Install the SDK if you want to follow the Node.js example.
npm i @unipile/sdk
pnpm add unipile

Create a client with your API key:

import { UnipileMessaging } from "unipile";

const key = "apikey";
const messagingApi = new UnipileMessaging({ key });

1. Link an account

In the Accounts section of the Dashboard, click Link account and select Google Messages.

Scan the QR code from the Google Messages app on the Android phone you want to connect. Keep the phone online once the account is linked.

When the account is added, keep the generated account ID. It will be used in the next steps.


2. List chats

To retrieve the conversations of the account acc_1234567890, use List all Chats:

const chats = await messagingApi.getChatsList({
  path: {
    account_id: "acc_1234567890",
  },
});
curl --request GET \
     --url https://api.unipile.com/v2/acc_1234567890/chats \
     --header 'X-API-KEY: api-key' \
     --header 'accept: application/json'

3. Send a first message

To start a new conversation, use Start a Chat and provide the recipient phone number in users_ids.

await messagingApi.startChat({
  path: {
    account_id: "acc_1234567890",
  },
  body: {
    users_ids: "+33644556677",
    text: "Hello from Unipile!",
  },
});
curl --request POST \
     --url https://api.unipile.com/v2/acc_1234567890/chats \
     --header 'X-API-KEY: api-key' \
     --header 'accept: application/json' \
     --header 'content-type: application/json' \
     --data '
{
  "users_ids": "+33644556677",
  "text": "Hello from Unipile!"
}
'
📘

Note

Google Messages accepts phone numbers in users_ids. Unipile normalizes common international formats automatically.


4. Discover Unipile fundamentals