Conversation API
Opt-in
By default, you can use the Opt-in URL that was generated in the dashboard. But if you need customization, you can try generating a unique URL for each user. Using this method helps with the following things:
- End-toEnd analytics
- Tracking users
- Attach custom data to each opt-in
- Generate a unique text for each opt-in
Backend method
This approach helps that you generate a unique URL on your backend, which is then passed to the frontend. When generating a URL, you can include various parameters that will be passed in a webhook once a user successfully init a conversation.
POST https://a.loopmessage.com/api/v1/opt-in/generate-url/
Headers
| Name | Type | Description |
|---|---|---|
| Authorization* | String | API Key. Required*. |
| Content-Type* | String | application/json |
Request Body
| Name | Type | Description |
|---|---|---|
| body | String | Text that will be prefilled in the destination app |
Any other fields that you pass in the JSON will be returned in the webhook when the user completes the opt-in process.
Request with custom Body example:
{
"body": "Hey guy, want to test end-to-end analytics a little? [opt-in-code]",
"click_id": "your-unique-id",
"utm_campaign": "quick-loan",
"utm_medium": "google"
}
In case of customize opt-in text, you can use the next method: body with [opt-in-code] as a required tag. The server replaces [opt-in-code] with a unique user code, which is required by the system to match opt-in with a specific contact.
In case of using shared sender names, you will need to include the next parameter in the request:
{
...
"sender_type": "shared"
}
Response
The API response contains unique links generated for the provided data. Example response:
{
"id": "3718be9c-17bc-412e-9790-c4768ca5df3e",
"imessage": "imessage://ahoy%40imsg.tel&body=Hey%20guy%2C%20want%20to%20test%20end-to-end%20analytics%20a%20little%3F%20%22%23FHyh-%21dfaN%22",
"sms": "sms:ahoy%40imsg.tel&body=Hey%20guy%2C%20want%20to%20test%20end-to-end%20analytics%20a%20little%3F%20%22%23FHyh-%21dfaN%22",
"whatsapp: "whatsapp://send?phone=hi%40imsg.co&text=hello%20%22%232M6t-%21DXSy%22%20world",
"url": "https://opt-in.imsg.link/opt-in/0Rig0/?id=3718be9c-17bc-412e-9790-c4768ca5df3e&body=Hey%20guy%2C%20want%20to%20test%20end-to-end%20analytics%20a%20little%3F%20%22%5Bopt-in-code%5D%22"
}
Use any of these links to redirect users to the destination messaging app.
Webhook example
{
"contact": "+155566678958",
"event": "message_inbound",
"language": {
"code": "en",
"name": "English"
},
"message_id": "2a12f7ed-da37-49fd-bbf9-e2965adfb01d",
"organization_id": "e2229e7b-29df-486d-924e-7dae925b0796",
"parameters": {
"click_id": "your-unique-id",
"utm_medium": "google",
"utm_campaign": "quick-loan"
},
"text": "Hey guy, want to test end-to-end analytics a little?",
"type": "opt_in",
"webhook_id": "d37985d1-d648-4d42-ac69-ae72e08da86e"
}
Frontend method
GET https://t.imsg.link/tracker-api/v1/generate-url/{organization_id}/
Use this method only from your frontend. This method checks the user-agent value. If it is detected that a request is sent from the backend framework, your request will fail.
Additional parameters are passed as GET query parameters.
Headers
There are no headers required. Authentication is not needed.
Path parameter
| Name | Type | Description |
|---|---|---|
| organization_id* | String | Required. Your organization ID. |
Query parameters
| Name | Type | Description |
|---|---|---|
| body | String | Text that will be prefilled in the destination app |
Example Request
Example URL with parameters:
GET https://t.imsg.link/tracker-api/v1/generate-url/{organization_id}/?body=hello[opt-in-code]¶m1=abcd
Example Response
{
"id": "6ad46341-4c91-4d01-a943-ea97f8e00d74",
"imessage": "imessage://hi%40imsg.co&body=hello%20%22%232M6t-%21DXSy%22%20world",
"sms": "sms:hi%40imsg.co&body=hello%20%22%232M6t-%21DXSy%22%20world",
"whatsapp: "whatsapp://send?phone=hi%40imsg.co&text=hello%20%22%232M6t-%21DXSy%22%20world",
"url": "https://opt-in.imsg.link/opt-in/5cTjZ/?id=6ad46341-4c91-4d01-a943-ea97f8e00d74&body=hello%20%5Bopt-in-code%5D%20world" }
}
In case of using shared sender names, you will need to include sender_type=shared query parameter in the request:
GET https://t.imsg.link/tracker-api/v1/generate-url/{organization_id}/?body=...&sender_type=shared
Key points
- The backend method helps provide more control over URL generation and avoid CORS restrictions.
- The response contains links for user interaction:
- iMessage: For iOS 13 and above.
- SMS: For iOS 12 and below, Android, and desktop devices.
- When using smart links (https URLs from the response), the user must grant the browser permission to open the Messages app. Currently, this URL works only on Apple devices.