API Gọi ra theo chiến dịch
Thêm danh sách liên hệ vào các chiến dịch đã được lên kịch bản sẵn.
Tiền điều kiện:
Đã tạo ứng dụng trên hệ thống AICall Cloud (xem cách tạo)
Đối với tài khoản trả trước: Số dư khả dụng còn đủ để thực hiện cuộc gọi (bảng giá dịch vụ)
Đã tạo ACCESS_TOKEN (xem cách tạo)
Chi tiết API:
Thêm danh sách liên hệ vào chiến dịch
POST https://aicall.vbee.ai/api/v1/public-api/campaign
(*) Trường bắt buộc
Headers
Authorization*
String
Bearer <ACCESS_TOKEN>
Request Body
campaign_id*
String
Mã chiến dịch
{
"result": [
{
"contact_id": "f95c4831-bc9d-4626-8713-a0a161cee01e",
"danh_xung": "Anh",
"ho_ten": "David Thiêm",
"so_dien_thoai": "+84987654321"
}
],
"status": 1
}Liên hệ
phone_number
String
Có
Số điện thoại của khách gọi tới
ho_ten
String
Không
Tên khách gọi tới (thẻ cá nhân hóa)
Ngoài tham số bắt buộc phone_number, mỗi liên hệ sẽ có thêm các giá trị của các thẻ cá nhân hóa (nếu có) khi bạn biên tập kịch bản cho chiến dịch. Ví dụ: thẻ cá nhân hóa ho_ten.
Kết quả trả về các liên hệ được thêm vào chiến dịch thành công. Mỗi liên hệ sẽ được đặt định danh là contact_id
Nếu bạn có kích hoạt webhook, xem định dạng dữ liệu trả về ở mục Webhook API
Danh sách mã lỗi
Nội dung lỗi trả về có thuộc tính status luôn là 0. Ví dụ:
{
"status": 0,
"code": 401,
"message": "Unauthorized"
}Danh sách mã lỗi:
401
Unauthorized
ACCESS_TOKEN không hợp lệ
500
Lỗi hệ thống
1201
Application is not found
Không tìm thấy ứng dụng
(kiểm tra lại thông tin API_KEY)
1402
Import contacts failed
Thêm khách hàng thất bại
1403
All contacts is invalid
Tất cả các khách hàng không hợp lệ
(Kiếm tra lại trường phone_number)
Code mẫu
const axios = require('axios');
const jwt = require('jsonwebtoken');
const API_KEY = '<API_KEY>';
const API_SECRET = '<API_SECRET>';
const CAMPAIGN_ID = '<CAMPAIGN_ID>';
const URL = 'https://aicall.vbee.ai/api/v1/public-api/campaign';
const ACCESS_TOKEN = jwt.sign(
{ apiKey: API_KEY },
API_SECRET,
);
axios({
method: 'POST',
url: URL,
headers: {
Authorization: `Bearer ${ACCESS_TOKEN}`,
},
data: {
campaign_id: CAMPAIGN_ID,
contacts: [
{
phone_number: '',
ho_ten: '',
},
],
},
});
import requests
import jwt
API_KEY = '<API_KEY>'
API_SECRET = '<API_SECRET>'
CAMPAIGN_ID = '<CAMPAIGN_ID>'
URL = 'https://aicall.vbee.ai/api/v1/public-api/campaign'
ACCESS_TOKEN = jwt.encode({apiKey: API_KEY}, API_SECRET)
requests.post(
url= {URL},
headers={
"Authorization": f"Bearer {ACCESS_TOKEN}",
},
json={
"campaign_id": {CAMPAIGN_ID},
"contacts": [
{
"phone_number":"",
"ho_ten":""
}
]
}
)
package org.example;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.google.gson.Gson;
import java.io.IOException;
import java.util.*;
public class Main {
public static void main(String[] args) {
OkHttpClient client = new OkHttpClient();
String API_KEY = "<API_KEY>";
String API_SECRET = "<API_SECRET>";
String CAMPAIGN_ID = "<CAMPAIGN_ID>";
String URL = "https://aicall.vbee.ai/api/v1/public-api/campaign";
Map<String, Object> data = new HashMap<>();
data.put("campaign_id", CAMPAIGN_ID);
List<Map<String, Object>> contacts = new ArrayList<>();
Map<String, Object> contact1 = new HashMap<>();
contact1.put("phone_number", "");
contact1.put("ho_ten", "");
contacts.add(contact1);
data.put("contacts", contacts);
String ACCESS_TOKEN = generateJWT(API_KEY, API_SECRET);
Gson gson = new Gson();
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), gson.toJson(data));
Request request = new Request.Builder()
.url(URL)
.header("Authorization", "Bearer " + ACCESS_TOKEN)
.post(requestBody)
.build();
try {
Response response = client.newCall(request).execute();
} catch (IOException e) {
e.printStackTrace();
}
}
private static String generateJWT(String apiKey, String apiSecret) {
Algorithm algorithm = Algorithm.HMAC256(apiSecret);
// Include the "iat" claim with the current timestamp
long currentTimeMillis = System.currentTimeMillis();
String token = JWT.create()
.withClaim("apiKey", apiKey)
.withIssuedAt(new Date(currentTimeMillis)) // Include "iat" claim
.sign(algorithm);
return token;
}
}
<?php
use \Firebase\JWT\JWT;
$API_KEY = '<API_KEY>';
$API_SECRET = '<API_SECRET>';
$CAMPAIGN_ID = '<CAMPAIGN_ID>';
$URL = 'https://aicall.vbee.ai/api/v1/public-api/campaign';
$payload = array(
"apiKey" => $API_KEY
);
$ACCESS_TOKEN = JWT::encode($payload, $API_SECRET, 'HS256');
$data = array(
"campaign_id" => $CAMPAIGN_ID,
"contacts" => array(
array(
"phone_number" => "",
"ho_ten" => ""
)
)
);
$ch = curl_init($URL);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer ' . $ACCESS_TOKEN,
'Content-Type: application/json'
));
$response = curl_exec($ch);
curl_close($ch);
echo $response;
Last updated