所有代理都属于一个品牌(商家、组织或群组)。在客服人员之前 必须创建一个自有品牌。品牌完全是 帮助您将相关代理归入一组
此页面上的代码段取自 Java 示例 和 Node.js 示例。
创建代理
如需创建 RBM 代理,您需要定义其基本信息。
Node.js
const businessCommunicationsApiHelper = require('@google/rbm-businesscommunications'); const privateKey = require('../../resources/businesscommunications-service-account-credentials.json'); businessCommunicationsApiHelper.initBusinessCommunucationsApi(privateKey); const newAgentDetails = { displayName: 'My new agent', name: brandId + '/agents/', rcsBusinessMessagingAgent: { description: 'This is the agent description that will be displayed in the Agent info tab in Messages', logoUri: 'https://agent-logos.storage.googleapis.com/_/kt90w53vzw2QSxK6PG1uCeJf', heroUri: 'https://agent-logos.storage.googleapis.com/_/kt90vzob74GQcfeHoEQbVRTP', phoneNumbers: [ { phoneNumber: { number: '+12223334444' }, label: 'Call support' } ], // emails and websites are optional privacy: { "uri": 'https://policies.google.com/privacy', "label": 'Our privacy policy' }, termsConditions: { "uri": 'https://policies.google.com/terms', "label": 'Our Terms and Conditions' }, color: '#0B78D0', billingConfig: { billingCategory: 'BASIC_MESSAGE' }, agentUseCase: 'TRANSACTIONAL', hostingRegion: 'EUROPE' } }; businessCommunicationsApiHelper.createAgent(brandId, newAgentDetails).then((response) => { }).catch((err) => { console.log(err); });
Java
Brand brand = api.getBrand(brandId); logger.info("Brand to operate on: " + brand); String displayName = flags.getOrDefault("agent_name", "Test RBM Agent: " + now.getSecond()); String suffix = flags.getOrDefault("agent_data_suffix", "API"); RcsBusinessMessagingAgent agentData = AgentFactory.createRbmAgent(suffix); Agent agent = api.createRbmAgent(brand, displayName, agentData); logger.info("RBM agent has been created: " + agent);
此代码会返回新的代理信息和唯一标识符 分配给该代理:
{
name: 'brands/40bd963f-ff92-425c-b273-8f0892d2d017/agents/my_new_agent_dxuewtvy_agent',
displayName: 'My new agent',
rcsBusinessMessagingAgent: {
description: 'This is the agent description that will be displayed in the Agent info tab in Messages',
logoUri: 'https://agent-logos.storage.googleapis.com/_/kt90w53vzw2QSxK6PG1uCeJf',
heroUri: 'https://agent-logos.storage.googleapis.com/_/kt90vzob74GQcfeHoEQbVRTP',
phoneNumbers: [ [Object] ],
privacy: {
uri: 'https://policies.google.com/privacy',
label: 'Our privacy policy'
},
termsConditions: {
uri: 'https://policies.google.com/terms',
label: 'Our Terms and Conditions'
},
color: '#0B78D0',
billingConfig: { billingCategory: 'BASIC_MESSAGE' },
agentUseCase: 'MULTI_USE',
hostingRegion: 'EUROPE'
}
}
查找代理定义
您可以使用代理的唯一标识符 (name
) 进行检索。
Node.js
const businessCommunicationsApiHelper = require('@google/rbm-businesscommunications'); const privateKey = require('../../resources/businesscommunications-service-account-credentials.json'); businessCommunicationsApiHelper.initBusinessCommunucationsApi(privateKey); // Retrieve details of the first agent (if one has already been created) businessCommunicationsApiHelper.getAgent(agent.name).then((response) => { }).catch((err) => { console.log(err); });
Java
Agent agent = api.getAgent(flags.get("agent_id")); logger.info("Agent: " + agent);
此代码会返回代理信息:
{
name: 'brands/40bd963f-ff92-425c-b273-8f0892d2d017/agents/my_new_agent_dxuewtvy_agent',
displayName: 'My new agent',
rcsBusinessMessagingAgent: {
description: 'This is the agent description that will be displayed in the Agent info tab in Messages',
logoUri: 'https://agent-logos.storage.googleapis.com/_/kt90w53vzw2QSxK6PG1uCeJf',
heroUri: 'https://agent-logos.storage.googleapis.com/_/kt90vzob74GQcfeHoEQbVRTP',
phoneNumbers: [ [Object] ],
privacy: {
uri: 'https://policies.google.com/privacy',
label: 'Our privacy policy'
},
termsConditions: {
uri: 'https://policies.google.com/terms',
label: 'Our Terms and Conditions'
},
color: '#0B78D0',
billingConfig: { billingCategory: 'BASIC_MESSAGE' },
agentUseCase: 'MULTI_USE',
hostingRegion: 'EUROPE'
}
}
提交验证信息
品牌验证 必须具有此权限才能发布代理。您必须于 之前提交验证信息 发出启动请求请注意,您无需等待品牌审批 然后再提出发布请求;品牌审批是在产品发布期间进行的 审批流程
Node.js
const businessCommunicationsApiHelper = require('@google/rbm-businesscommunications'); const privateKey = require('../../resources/businesscommunications-service-account-credentials.json'); businessCommunicationsApiHelper.initBusinessCommunucationsApi(privateKey); let agentVerificationContact = { partnerName: 'Alice', partnerEmailAddress: 'alice@thepartner.com', brandContactName: 'Bob', brandContactEmailAddress: 'bob@thebrand.com', brandWebsiteUrl: 'https://thebrand.com/' }; businessCommunicationsApiHelper.verifyAgent(agent.name, agentVerificationContact).then((response) => { }).catch((err) => { console.log(err); });
Java
AgentVerificationContact contact = AgentFactory.createRbmAgentVerification(); AgentVerification verification = api.requestAgentVerification(agent.getName(), contact); logger.info("Verification requested: " + verification);
此代码会返回验证信息:
{
"name": "brands/40bd963f-ff92-425c-b273-8f0892d2d017/agents/my_new_agent_ciymyd2b_agent",
"verificationState": "VERIFICATION_STATE_UNVERIFIED",
"agentVerificationContact": {
"partnerName": "Alice",
"partnerEmailAddress": "alice@thepartner.com",
"brandContactName": "Bob",
"brandContactEmailAddress": "bob@thebrand.com",
"brandWebsiteUrl": "https://thebrand.com/"
}
}
查询代理的验证状态
您可以查询代理的品牌验证状态。
Node.js
const businessCommunicationsApiHelper = require('@google/rbm-businesscommunications'); const privateKey = require('../../resources/businesscommunications-service-account-credentials.json'); businessCommunicationsApiHelper.initBusinessCommunucationsApi(privateKey); businessCommunicationsApiHelper.getAgentVerification(agent.name).then((response) => { }).catch((err) => { console.log(err); });
Java
AgentVerification verification = api.getAgentVerification(agent.getName()); logger.info("RBM agent verification: " + verification);
此代码会返回验证状态:
{
"name": "brands/40bd963f-ff92-425c-b273-8f0892d2d017/agents/my_new_agent_ciymyd2b_agent/verification",
"verificationState": "VERIFICATION_STATE_UNVERIFIED",
"agentVerificationContact": {}
}
提交代理以供发布
您可以提交代理,以供一个或多个运营商发布。部分发布 由 Google 管理,其他平台则由运营商直接管理。通过 运营商管理的发布可能还有其他要求。请参阅 由 Google 管理的发布与由运营商管理的发布 。
首次发布代理之前,您需要: 提交验证信息。 这样,Google、运营商或两者就能够向您的品牌联系人进行验证, 您有权代表他们管理此代理。请参阅 品牌验证 了解详情。
提交验证信息并填写 发布前提条件 您可以提交发布请求
您可以提交代理,以供一个或多个运营商发布。已完成的 发布调查问卷时必须填写。
Node.js
const businessCommunicationsApiHelper = require('@google/rbm-businesscommunications'); const privateKey = require('../../resources/businesscommunications-service-account-credentials.json'); businessCommunicationsApiHelper.initBusinessCommunucationsApi(privateKey); let agentLaunch = { questionnaire: { contacts: [ { name: 'James Bond', title: 'Mr 0 0 7', email: 'someone@somewhere.com' } ], optinDescription: 'Users accepted our terms of service online.', triggerDescription: 'We are reaching preregistered users', interactionsDescription: 'This agent does not do much.', optoutDescription: 'Reply stop and we stop.', agentAccessInstructions: 'This is a a simple agent that reaches registered users.', videoUris: [ 'https://www.google.com/a/video' ], screenshotUris: [ 'https://www.google.com/a/screenshot' ] }, launchDetails: {} }; businessCommunicationsApiHelper.launchAgent(agent.name, agentLaunch).then((response) => { }).catch((err) => { console.log(err); });
Java
Optional<Questionnaire> q = Optional.of(AgentFactory.createRbmQuestionnaire()); AgentLaunch launch = api.requestRbmAgentLaunch(agent.getName(), regionIds, q); logger.info("RBM agent updated launch: " + launch);
此代码会返回代理发布信息:
{
"name": "brands/40bd963f-ff92-425c-b273-8f0892d2d017/agents/my_new_agent_7jo0trhw_agent/launch",
"rcsBusinessMessaging": {
"questionnaire": {
"contacts": [
{
"name": "James Bond",
"title": "Mr O O 7",
"email": "someone@somewhere.com"
}
],
"optinDescription": "Users accepted our terms of service online.",
"triggerDescription": "We are reaching preregistered users",
"interactionsDescription": "This agent does not do much.",
"optoutDescription": "Reply stop and we stop.",
"agentAccessInstructions": "This is a a simple agent that reaches registered users.",
"videoUris": [
"https://www.google.com/a/video"
],
"screenshotUris": [
"https://www.google.com/a/screenshot"
]
},
"launchDetails": {
"/v1/regions/some-carrier": {
"launchState": "LAUNCH_STATE_PENDING",
"updateTime": "2023-02-24T15:02:13.903554Z"
}
},
"launchRegion": "NORTH_AMERICA"
}
}
请注意,launchRegion
已被弃用,我们很快就会将其移除。
查询代理的发布状态
您可以检索代理的当前发布状态。
Node.js
const businessCommunicationsApiHelper = require('@google/rbm-businesscommunications'); const privateKey = require('../../resources/businesscommunications-service-account-credentials.json'); businessCommunicationsApiHelper.initBusinessCommunucationsApi(privateKey); businessCommunicationsApiHelper.getAgentLaunch(agent.name).then((response) => { }).catch((err) => { console.log(err); });
Java
AgentLaunch launch = api.getAgentLaunch(agent.getName()); logger.info("RBM agent launch: " + launch);
此代码会返回各应用的启动信息和启动状态 目标运营商:
{
"name": "brands/40bd963f-ff92-425c-b273-8f0892d2d017/agents/my_new_agent_7jo0trhw_agent/launch",
"rcsBusinessMessaging": {
"questionnaire": {
"contacts": [
{
"name": "James Bond",
"title": "Mr O O 7",
"email": "someone@somewhere.com"
}
],
"optinDescription": "Users accepted our terms of service online.",
"triggerDescription": "We are reaching preregistered users",
"interactionsDescription": "This agent does not do much.",
"optoutDescription": "Reply stop and we stop.",
"agentAccessInstructions": "This is a a simple agent that reaches registered users.",
"videoUris": [
"https://www.google.com/a/video"
],
"screenshotUris": [
"https://www.google.com/a/screenshot"
]
},
"launchDetails": {
"/v1/regions/some-carrier": {
"launchState": "LAUNCH_STATE_PENDING",
"updateTime": "2023-02-24T15:02:13.903554Z"
}
},
"launchRegion": "NORTH_AMERICA"
}
}
请注意,launchRegion
已被弃用,我们很快就会将其移除。
在发布代理时添加更多运营商
可通过检索当前发布添加其他目标运营商 信息并添加更多运营商。
Node.js
const businessCommunicationsApiHelper = require('@google/rbm-businesscommunications'); const privateKey = require('../../resources/businesscommunications-service-account-credentials.json'); businessCommunicationsApiHelper.initBusinessCommunucationsApi(privateKey);'); // To launch an agent to further carriers, we need to first obtain the existing // launch information and extend it with the new carrier(s). businessCommunicationsApiHelper.getAgentLaunch(agent.name).then((response) => { let existingLaunch = response.data.rcsBusinessMessaging; // Now we add the new carrier to the existing launch existingLaunch.launchDetails[config.launchCarrier2] = null; // And we submit the launch again businessCommunicationsApiHelper.launchAgent(agent.name, existingLaunch).then((response) => { console.log('Launch details are:'); console.log(JSON.stringify(response.data, null, 2)); }).catch((err) => { console.log(err); }); }).catch((err) => { console.log(err); });
此代码会返回更新后的发布信息:
{
"name": "brands/40bd963f-ff92-425c-b273-8f0892d2d017/agents/my_new_agent_7jo0trhw_agent/launch",
"rcsBusinessMessaging": {
"questionnaire": {
"contacts": [
{
"name": "James Bond",
"title": "Mr O O 7",
"email": "someone@somewhere.com"
}
],
"optinDescription": "Users accepted our terms of service online.",
"triggerDescription": "We are reaching preregistered users",
"interactionsDescription": "This agent does not do much.",
"optoutDescription": "Reply stop and we stop.",
"agentAccessInstructions": "This is a a simple agent that reaches registered users.",
"videoUris": [
"https://www.google.com/a/video"
],
"screenshotUris": [
"https://www.google.com/a/screenshot"
]
},
"launchDetails": {
"/v1/regions/some-carrier": {
"launchState": "LAUNCH_STATE_PENDING",
"updateTime": "2023-02-24T15:02:13.903554Z"
},
"/v1/regions/another-carrier": {
"launchState": "LAUNCH_STATE_PENDING",
"updateTime": "2023-02-24T15:04:50.456552Z"
}
},
"launchRegion": "NORTH_AMERICA"
}
}
列出为品牌创建的所有代理
开发者可以检索他们为品牌创建的所有代理的列表。
Node.js
const businessCommunicationsApiHelper = require('@google/rbm-businesscommunications'); const privateKey = require('../../resources/businesscommunications-service-account-credentials.json'); businessCommunicationsApiHelper.initBusinessCommunucationsApi(privateKey); businessCommunicationsApiHelper.listAgents(brand.name).then((response) => { console.log('Current agents are:'); console.log(response.data); datastore.saveJsonData('agents', response.data.agents); }).catch((err) => { console.log(err); });
Java
Brand brand = api.getBrand(brandId); logger.info("Brand: " + brand); ListAgentsResponse response = api.listAllAgents(brand); List<Agent> agents = response.getAgents().stream() .sorted(Comparator.comparing(Agent::getName)).collect(Collectors.toList()); logger.info(String.format("Found %d agents", response.getAgents().size())); for (Agent agent : agents) { logger.info(String.format("Agent [%s]: '%s'", agent.getName(), agent.getDisplayName())); }
此代码会返回品牌拥有的所有代理的列表:
{
agents: [
{
name: 'brands/40bd963f-ff92-425c-b273-8f0892d2d017/agents/my_new_agent_4fpd1psz_agent',
displayName: 'My new agent',
rcsBusinessMessagingAgent: [Object]
},
{
name: 'brands/40bd963f-ff92-425c-b273-8f0892d2d017/agents/my_new_agent_ciymyd2b_agent',
displayName: 'My second agent',
rcsBusinessMessagingAgent: [Object]
},
{
name: 'brands/40bd963f-ff92-425c-b273-8f0892d2d017/agents/my_new_agent_helof85o_agent',
displayName: 'My third agent',
rcsBusinessMessagingAgent: [Object]
}
]
}
删除代理
出于安全考虑,无法再删除 RBM 代理。联系 RBM 支持团队以获取帮助。