Learn how to link a Facebook account, list inboxes, and send your first Messenger message with Unipile.
Prerequisites
Before we start, you need to:
- Signup to Unipile.
- Create an Application in the dashboard.
- Create an API Key from the dashboard.
- Install the SDK if you want to follow the Node.js example.
npm i @unipile/sdkpnpm add unipileCreate 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 Facebook.
Open Messenger or Facebook Messages in the same browser, copy the required cookies, then paste them into the Unipile flow.
When the account is added, keep the generated account ID. It will be used in the next steps.
Business and Page inboxesQuick Add uses the default Messenger surface. If the account primarily manages Page or Business Suite inboxes, generate a custom auth link with
config.facebook.surface = "facebook"instead.
2. List inboxes
Facebook uses several inboxes in Unipile, such as INBOX, PENDING, OTHER, and ARCHIVED.
curl --request GET \
--url https://api.unipile.com/v2/acc_1234567890/inboxes \
--header 'X-API-KEY: api-key' \
--header 'accept: application/json'3. List chats
To retrieve chats from the main Facebook inbox, use List inbox Chats:
curl --request GET \
--url https://api.unipile.com/v2/acc_1234567890/inboxes/INBOX/chats \
--header 'X-API-KEY: api-key' \
--header 'accept: application/json'4. Send a first message
To start a new Facebook conversation, use Start a Chat with a numeric user ID, public identifier, or Facebook profile/page URL.
await messagingApi.startChat({
path: {
account_id: "acc_1234567890",
},
body: {
users_ids: "https://www.facebook.com/zuck",
text: "Hello from Unipile!",
},
});curl --request POST \
--url https://api.unipile.com/v2/acc_1234567890/chats/send \
--header 'X-API-KEY: api-key' \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--data '
{
"users_ids": "https://www.facebook.com/zuck",
"text": "Hello from Unipile!"
}
'5. Discover Unipile fundamentals
Updated 14 days ago