Channels

Connect and manage messaging channels

Channels

In order to receive and send messages, you need to connect channels. Channels is a source of incoming messages in the system. Channel providers:

  • MAX
  • WhatsApp
  • Instagram_business
  • Telegram
  • Telegram Personal
  • Viber
  • VK
  • Facebook

You can also connect required channels via our web interface under the settings page.

Get All channels

shell
curl "https://api.pact.im/p1/companies/COMPANY_ID/channels"
  -H "X-Private-Api-Token: YOUR_API_TOKEN"

The above command returns JSON structured like this:

json
{
   "status":"ok",
   "data":{
      "channels":[
         {
            "external_id":399,
            "provider":"whatsapp"
         }
      ],
      "next_page": "fslkfg2lkdfmlwkmlmw4of94wg34lfkm34lg"
   }
}

This endpoint returns all the company channels.

HTTP Request

GET https://api.pact.im/p1/companies/<COMPANY_ID>/channels

Query Parameters

ParameterRequiredValidationsDescription
fromfalseMust be a String not more than 255 symbolsNext page token geted from last request. Not valid or empty token return first page
perfalseMust be a number between 1 and 100Number of elements per page. Default: 50
sort_directionfalseMust be a StringWe sort results by id. Change sorting direction. Avilable values: asc, desc. Default: asc.

URL Parameters

ParameterDescription
COMPANY_IDID of the company

Create new channel

shell
curl -X POST "https://api.pact.im/p1/companies/COMPANY_ID/channels"
  -H "X-Private-Api-Token: YOUR_API_TOKEN"
  -d "provider=telegram&token=12345677890"

Create channel:

php
<?php

/**
 * Unified method that can create channel in company.
 * @link https://pact-im.github.io/api-doc/#create-new-channel
 * @note You can connect only one channel per one company for each provider.
 *       Contact with support if you want to use more than one channel
 *
 * @param int $companyId Id of the company
 * @param string $provider
 * @param array $parameters
 */

// # Create channel unified method
// Note: The array of parameters variables depending on the provider
//       You need add required parameters for your particular provider

$parameters = [
  'sync_messages_from' => $syncMessagesFrom
  // ...
];

$client->channels->createChannelUnified($companyId,
                                        $provider,
                                        $parameters);

Create whatsapp channel:

php
<?php

/**
 * This method create a new channel for WhatsApp
 * @link https://pact-im.github.io/api-doc/#create-new-channel
 *
 * @param int $companyId Id of the company
 * @param DateTimeInterface $syncMessagesFrom Only messages created after will be synchronized
 * @param bool $doNotMarkAsRead Do not mark chats as read after synchronization
 * @return Json|null
 */

$client->channels->createChannelWhatsApp(
  $companyId,
  $syncMessagesFrom,
  $doNotMarkAsRead,
  $phone
);

Create instagram business channel:

php
<?php

/**
 * This method create a new channel for InstagramBusiness
 * @link https://pact-im.github.io/api-doc/#create-new-channel
 *
 * @param int $companyId Id of the company
 * @param string $private_api_token on our side
 * @param string $provider there must be "instagram_business"
 * @param hash $data data from Instagram
 * @param string $token from Instagram data hash
 * @param string $phone user phone
 * @return Json|null
 */

$client->channels->createChannelInstagramBusiness(
  $companyId,
  $private_api_token,
  $provider,
  $data,
  $token
  $phone
);

Create facebook/vkontakte/vkontakte_direct/telegram/viber channel

php
<?php

/**
 * This method create a new channel in the company using token.
 * @link https://pact-im.github.io/api-doc/#create-new-channel
 * @note List of supported channels that can be created by token
 *       you can see in link above
 *
 * @param int $companyId Id of the company
 * @param string $provider (facebook, viber, vk, ...)
 * @param string $token
 * @return Json|null
 */

$client->channels->createChannelByToken(
  $companyId,
  $provider,
  $token
);

The above command returns JSON structured like this:

json
{
   "status": "created",
   "data": {
      "external_id": 1
   }
}

This endpoint create a new channel in the company.

HTTP Request

POST https://api.pact.im/p1/companies/<COMPANY_ID>/channels

URL Parameters

ParameterDescription
COMPANY_IDID of the company

Query Parameters

Create max channel (by qr code)
ParameterRequiredValidationsDescription
providertrueMust be max
sync_messages_fromfalsetimestampOnly messages created after sync_messages_from will be synchronized. Not older than one month. If the parameter is not specified, no messages will be synchronized.
Create whatsapp channel (by qr code)
ParameterRequiredValidationsDescription
providertrueMust be whatsapp
sync_messages_fromfalsetimestampOnly messages created after sync_messages_from will be synchronized. Not older than one month. If the parameter is not specified, no messages will be synchronized.
Create whatsapp channel (by digital code)
ParameterRequiredValidationsDescription
providertrueMust be whatsapp
sync_messages_fromfalsetimestampOnly messages created after sync_messages_from will be synchronized. Not older than one month. If the parameter is not specified, no messages will be synchronized.
phonetruestringPhone number. Example: ‘7999999999’
Create whatsapp business channel (dialog360 by token)
ParameterRequiredValidationsDescription
providertrueMust be whatsapp_business
hosting_typetrueMust be a cloud, onpremiseHosting platform type
tokentrueMust be a StringToken for auth.
subtypefalseMust be a regular, unlim, no_write_firstTarif name
Create whatsapp business channel (dialog360 by channel_id)
ParameterRequiredValidationsDescription
providertrueMust be whatsapp_business
hosting_typetrueMust be a cloud, onpremiseHosting platform type
dialog360_channel_idtrueMust be a Stringchannel_id for auth
dialog360_client_idfalseMust be a Stringclient_id for auth
account_namefalseMust be a StringAccount name for waba profile
subtypefalseMust be a regular, unlim, no_write_firstTarif name
Create avito channel
ParameterRequiredValidationsDescription
providertrueMust be avito
logintrueMust be a Stringavito client_id
passwordtrueMust be a Stringavito client secret
Create instagram business channel

Steps:

  1. It is necessary to follow the instructions for Facebook until you receive the token.

  2. Make a request for https://graph.facebook.com/v4.0/me?fields=first_name,last_name,picture,name,email indicating the token.
    In the response you will receive information about your user.

  3. Send a request to us p1/companies/<company_id>/channels.
    The request body must contain:

    • provider: "instagram_business"
    • token: "token"
    • phone: "+79131112233"
    • data: "response body to previous request"

    At this stage, a channel was created and information on Instagram business accounts was uploaded.

  4. Send a request to p1/companies/<company_id>/channels/<external_id>/enable_page_instagram?page_id=<page[:id]>&sync_period=<sync_period>.

    external_id - parameter from previous request
    page[:id] - parameter from previous request
    sync_period - used to determine what period of messages will be synchronized: day, week, month, all.

    This is necessary in order to determine which Instagram account to use.

ParameterRequiredValidationsDescription
providertrueMust be instagram_business
private_api_tokentrueStringUser privat token
datatrueHashData from Instagram that was transferred to redirect_url
phonetrueStringUser phone
tokentrueStringInstagram token
Create facebook/vkontakte/vkontakte_direct/telegram/viber channel
ParameterRequiredValidationsDescription
providertrueMust be one of: facebook, vkontakte, vkontakte_direct, telegram, viberShows which provider you want to connect
tokentrueMust be a StringToken for auth.
Create telegram personal channel (by qr code)
ParameterRequiredValidationsDescription
providertrueMust be telegram_personal
via_qr_codetruebooleanMust be a 'true'
sync_messages_fromfalsetimestampOnly messages created after sync_messages_from will be synchronized. Not older than one month. If the parameter is not specified, no messages will be synchronized.
Create telegram personal channel (by digital code)
ParameterRequiredValidationsDescription
providertrueMust be telegram_personal
phonetrueMust be a StringPhone number. Example: '7999999999'
sync_messages_fromfalsetimestampOnly messages created after sync_messages_from will be synchronized. Not older than one month. If the parameter is not specified, no messages will be synchronized.

Request code Confirm code

Get token for vk group:
  1. Open "Manage" in selected group
  2. Open "API usage" (https://vk.com/public<GROUP_ID>?act=tokens)
  3. Create and copy new token

Update channel

shell
curl -X PUT "https://api.pact.im/p1/companies/COMPANY_ID/channels/ID"
  -H "X-Private-Api-Token: YOUR_API_TOKEN"
  -d "token=9876543210"

Update channel:

php
<?php

/**
 * This method updates existing channel in the company
 * @link https://pact-im.github.io/api-doc/#update-channel
 *
 * @param int $companyId
 * @param int $conversationId
 * @param array $parameters
 * @return Json|null
 */

// # Update channel unified method
// Note: The array of parameters variables depending on the provider
//       You need add required parameters for your particular provider

$parameters = [
  'login' => $login,
  'password' => $password,
  // ...
];

$client->channels->updateChannel(
  $companyId,
  $conversationId,
  $parameters
);

Update instagram channel:

php
<?php

/**
 * This method updates instagramm channel
 * @link https://pact-im.github.io/api-doc/#update-channel
 *
 * @param int $companyId
 * @param int $conversationId
 * @param string $login Instagram login
 * @param string $password Instagram password
 * @return Json|null
 */

$client->channels->updateChannelInstagram(
  $companyId,
  $conversationId,
  $login,
  $password
);

Update facebook/vkontakte/vkontakte_direct/telegram/viber channel:

php
<?php

/**
 * This method updates channels that using tokens to auth
 * @link https://pact-im.github.io/api-doc/#update-channel
 * @note List of supported channels that can be created by token
 *       you can see in link above
 *
 * @param int $companyId
 * @param int $conversationId
 * @param string $token
 * @return Json|null
 */

$client->channels->updateChannelToken(
  $companyId,
  $conversationId,
  $token
);

The above command returns JSON structured like this:

json
{
   "status":"updated",
   "data":{
      "external_id":2
   }
}

This endpoint updates existing channel in the company.

HTTP Request

PUT https://api.pact.im/p1/companies/<COMPANY_ID>/channels/<ID>

URL Parameters

ParameterDescription
COMPANY_IDID of the company
IDID of the channel

Query Parameters

For facebook/vkontakte/vkontakte_direct/telegram/viber/instagram_business channels
ParameterRequiredValidationsDescription
tokentrueMust be a String...

Delete channel

shell
curl -X DELETE "https://api.pact.im/p1/companies/COMPANY_ID/channels/ID"
  -H "X-Private-Api-Token: YOUR_API_TOKEN"

Delete channel:

php
<?php
/**
 * Method deletes (disables) the channel
 * @link https://pact-im.github.io/api-doc/#delete-channel
 *
 * @param int $companyId Id of the company
 * @param int $channelId Id of the conversation
 */

$client->chanells->deleteChannel($companyId, $channelId);

The above command returns JSON structured like this:

json
{
   "status":"deleted"
}

HTTP Request

DELETE https://api.pact.im/p1/companies/<COMPANY_ID>/channels/<ID>

URL Parameters

ParameterDescription
COMPANY_IDID of the company
IDID of the channel for disable

How to write first message to Whatsapp Business

shell
curl -X POST "https://api.pact.im/p1/companies/COMPANY_ID/channels/ID/conversations"
  -H "X-Private-Api-Token: YOUR_API_TOKEN"
  -d "phone=79250000001&template[id]=template_id&template[language_code]=ru&template[parameters][]=имя"

This endpoint provides an ability to create conversation with a client in whatsapp channel. When you execute this request we will add a job for delivery. We will send webhook when the operation is complete or failed.

You can also poll delivery status here: Jobs

HTTP Request

POST https://api.pact.im/p1/companies/<COMPANY_ID>/channels/<ID>/conversations

URL Parameters

ParameterDescription
COMPANY_IDID of the company
IDID of the channel

Query Parameters

ParameterRequiredValidationsDescription
phonetrueMust be in format 79250000001Contact phone number
messagefalseMust be StringMessage text. For regular Whatsapp channel only
templatefalseMust be ObjectTemplate data. For Whatsapp Business channel only

Whatsapp Business Template Parameters

ParameterRequiredValidationsDescription
idtrueMust be StringID of registered template
language_codetrueMust be StringLanguage code of registered template ('en', 'ru', etc)
parameterstrueMust be ArrayTemplate substitution parameters

Request code (whatsapp)

Request code:

shell
curl -X POST "https://api.pact.im/p1/companies/COMPANY_ID/channels/ID/request_code"
  -H "X-Private-Api-Token: YOUR_API_TOKEN"
  -d "provider=whatsapp"

The above command returns JSON structured like this:

json
{
   "sessionId": "1426",
   "code": "ZHHJ-KQSP",
   "ttl": "160s"
}

In the WhatsApp mobile application, you will receive a notification asking you to insert an authorization code. Enter the value "code" there

HTTP Request

POST https://api.pact.im/p1/companies/<COMPANY_ID>/channels/<ID>/request_code

URL Parameters

ParameterDescription
COMPANY_IDID of the company
IDID of the channel
providerwhatsapp

Query Parameters

Request challenge code

Parameter | Required | Validations | Description --------- | -------- | ----------- | provider | true | Must be whatsapp |

Request code (telegram personal)

Request code:

shell
curl -X POST "https://api.pact.im/p1/companies/COMPANY_ID/channels/ID/request_code"
  -H "X-Private-Api-Token: YOUR_API_TOKEN"
  -d "provider=telegram_personal"

The above command returns JSON structured like this:

json
{
  "code_length": 6,
  "code_type": "app",
  "expires_in": 60,
  "next_type": "app",
  "session_id": 1337,
  "status": "ok"
}

This endpoint request code for telegram personal

HTTP Request

POST https://api.pact.im/p1/companies/<COMPANY_ID>/channels/<ID>/request_code

URL Parameters

ParameterDescription
COMPANY_IDID of the company
IDID of the channel

Query Parameters

Request challenge code

Parameter | Required | Validations | Description --------- | -------- | ----------- | provider | true | Must be telegram_personal |

Confirm code (telegram personal)

Confirmation type is code

shell
curl -X POST "https://api.pact.im/p1/companies/COMPANY_ID/channels/ID/confirm"
  -H "X-Private-Api-Token: YOUR_API_TOKEN"
  -d "provider=telegram_personal&confirmation_type=code&code=2567"

Successful response:

json
{
  "result": "ok",
  "state": "enabled"
}

Confirmirmation type is password

shell
curl -X POST "https://api.pact.im/p1/companies/COMPANY_ID/channels/ID/confirm"
  -H "X-Private-Api-Token: YOUR_API_TOKEN"
  -d "provider=telegram_personal&confirmation_type=password&password=123456"

The above command returns JSON structured like this:

json
{
  "result": "ok",
  "state": "enabled"
}

This endpoint confirm telegram personal channel with two types: code, password

HTTP Request

POST https://api.pact.im/p1/companies/<COMPANY_ID>/channels/<ID>/confirm

URL Parameters

ParameterDescription
COMPANY_IDID of the company
IDID of the channel

Query Parameters

Confirmation type is code

Parameter | Required | Validations | Description --------- | -------- | ----------- | provider | true | Must be telegram_personal | confirmation_type | true | Must be code | code | true | Must be a Number | Example: 1234

Confirmation type is password

Parameter | Required | Validations | Description --------- | -------- | ----------- | provider | true | Must be telegram_personal | confirmation_type | true | Must be password | password | true | Must be a String | Example: qwerty123

Request code (instagram only)

Request challenge code:

shell
curl -X POST "https://api.pact.im/p1/companies/COMPANY_ID/channels/ID/request_code"
  -H "X-Private-Api-Token: YOUR_API_TOKEN"
  -d "provider=instagram&challenge_variant=0"

The above command returns JSON structured like this:

json
{
  "result": "ok"
}

Request two factor authentication code:

shell
curl -X POST "https://api.pact.im/p1/companies/COMPANY_ID/channels/ID/request_code"
  -H "X-Private-Api-Token: YOUR_API_TOKEN"
  -d "provider=instagram&challenge_type=two_factor"

The above command returns JSON structured like this:

json
{
  "result": "ok"
}

This endpoint request challenge or two factor authentication code.

HTTP Request

POST https://api.pact.im/p1/companies/<COMPANY_ID>/channels/<ID>/request_code

URL Parameters

ParameterDescription
COMPANY_IDID of the company
IDID of the channel

Query Parameters

Request challenge code

Parameter | Required | Validations | Description --------- | -------- | ----------- | provider | true | Must be instagram | challenge_variant | true | |

Request two factor SMS authentication code
ParameterRequiredValidationsDescription
providertrueMust be instagram
challenge_typetrueMust be two_factor

Confirm code (instagram only)

Confirm challenge code:

shell
curl -X POST "https://api.pact.im/p1/companies/COMPANY_ID/channels/ID/confirm"
  -H "X-Private-Api-Token: YOUR_API_TOKEN"
  -d "provider=instagram&confirmation_code=123456"

The above command returns JSON structured like this.

Successful response:

json
{
  "result": "ok"
}

Two factor authentication required:

json
{
  "result": "ok",
  "data": {
    "two_factor_requires": true,
    "details": [
      { "value": 1, "key": "sms" },
      { "value": 2, "key": "recovery_code" },
      { "value": 3, "key": "totp" }
    ]
  }
}

Challenge required:

json
{
  "result": "ok",
  "data": {
    "confirmation_requires": true,
    "details": [
      { "value" => 1, "label" => "e*******e@example.org" },
      { "value" => 0, "label" => "+0 *** ***-**-00" }
    ]
  }
}

Confirm two factor authentication code:

shell
curl -X POST "https://api.pact.im/p1/companies/COMPANY_ID/channels/ID/confirm"
  -H "X-Private-Api-Token: YOUR_API_TOKEN"
  -d "provider=instagram&confirmation_type=two_factor&confirmation_variant=3&confirmation_code=123456"

The above command returns JSON structured like this:

json
{
  "result": "ok"
}

This endpoint submit challenge or two factor authentication code.

HTTP Request

POST https://api.pact.im/p1/companies/<COMPANY_ID>/channels/<ID>/confirm

URL Parameters

ParameterDescription
COMPANY_IDID of the company
IDID of the channel

Query Parameters

challenge code

Parameter | Required | Validations | Description --------- | -------- | ----------- | provider | true | Must be instagram | confirmation_code | true | Must be a String |

two factor authentication code

Parameter | Required | Validations | Description --------- | -------- | ----------- | provider | true | Must be instagram | confirmation_type| true | Must be two_factor | confirmation_variant | true | Must be a Integer | Variant from request code response (data->details->value). Typicaly 1, 2 or 3. confirmation_code | true | Must be a String |

Search…

Start typing to search