new_releases 更新:查看
版本資訊瞭解新功能和產品更新。
事件
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
在以下範例中,rbm_api_helper.js
(不供 Python 使用) 會假設您正在使用的檔案位於主應用程式資料夾下方一個目錄。視專案設定而定,您可能需要調整位置。
讀取事件
讀取事件可讓使用者知道代理程式已收到訊息,並讓他們放心,RBM 平台已傳送訊息。以下程式碼會將讀取事件傳送至裝置,並使用用戶端程式庫。
Node.js
// Reference to RBM API helper
const rbmApiHelper = require('@google/rcsbusinessmessaging');
// Send the device an event to indicate that messageId has been read
rbmApiHelper.sendReadMessage('+12223334444', messageId);
以下程式碼節錄自 RBM 範例服務專員。
Java
import com.google.rbm.RbmApiHelper;
…
// Create an instance of the RBM API helper
RbmApiHelper rbmApiHelper = new RbmApiHelper();
// Send the device an event to indicate that messageId has been read
rbmApiHelper.sendReadMessage(messageId, "+12223334444");
以下程式碼節錄自 RBM 範例服務專員。
Python
# Reference to RBM Python client helper and messaging object structure
from rcs_business_messaging import rbm_service
# Send the device an event to indicate that message_id was read
rbm_service.send_read_event('+12223334444', message_id)
以下程式碼節錄自 RBM 範例服務專員。
C#
using RCSBusinessMessaging;
…
// Create an instance of the RBM API helper
RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation,
projectId);
// Send the device an event to indicate that messageId has been read
rbmApiHelper.SendReadMessage(messageId, "+12223334444");
以下程式碼節錄自 RBM 範例服務專員。
輸入事件
輸入事件:讓使用者知道您的服務機器人正在撰寫訊息。以下程式碼會透過用戶端程式庫,將輸入事件傳送至裝置。
Node.js
// Reference to RBM API helper
const rbmApiHelper = require('@google/rcsbusinessmessaging');
// Send the device an event to indicate that the agent is typing
rbmApiHelper.sendIsTypingMessage('+12223334444', function() {
console.log('Typing event sent!');
});
這段程式碼是 RBM 範例服務專員的摘錄。
Java
import com.google.rbm.RbmApiHelper;
…
// Create an instance of the RBM API helper
RbmApiHelper rbmApiHelper = new RbmApiHelper();
// Send the device an event to indicate that the agent is typing
rbmApiHelper.sendIsTypingMessage("+12223334444");
這段程式碼是 RBM 範例服務專員的摘錄。
Python
# Reference to RBM Python client helper and messaging object structure
from rcs_business_messaging import rbm_service
# Send the device an event to indicate that the agent is typing
rbm_service.send_is_typing_event('+12223334444')
以下程式碼節錄自 RBM 範例服務專員。
C#
using RCSBusinessMessaging;
…
// Create an instance of the RBM API helper
RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation,
projectId);
// Send the device an event to indicate that the agent is typing
rbmApiHelper.SendIsTypingMessage(messageId, "+12223334444");
以下程式碼節錄自 RBM 範例服務專員。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-04-10 (世界標準時間)。
[null,null,["上次更新時間:2025-04-10 (世界標準時間)。"],[[["\u003cp\u003eRead events inform the user that the agent has received their message, confirming delivery by the RBM platform, with code examples provided for Node.js, Java, Python, and C#.\u003c/p\u003e\n"],["\u003cp\u003eTyping events signal to the user that the agent is currently composing a message, and examples using Node.js, Java, Python, and C# are shown.\u003c/p\u003e\n"],["\u003cp\u003eThe examples demonstrate how to use the RBM API helper to send read and typing events, across multiple programming languages.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003erbm_api_helper.js\u003c/code\u003e is designed for use in Node.js and assumes a specific directory structure, which might need adjustments based on your project's configuration.\u003c/p\u003e\n"]]],[],null,["# Events\n\nIn the following examples, `rbm_api_helper.js` (not used for Python) assumes the\nfile you are working in is one directory below the main app folder. You may need\nto adjust the location depending on your project's configuration.\n\nRead events\n-----------\n\n[Read events](/business-communications/rcs-business-messaging/guides/build/events#read) let the user know that the agent received the message and\nprovide confidence that the RBM platform delivered their message. The following\ncode sends a read event to a device with a client library. \n\n### Node.js\n\n```javascript\n// Reference to RBM API helper\nconst rbmApiHelper = require('@google/rcsbusinessmessaging');\n\n// Send the device an event to indicate that messageId has been read\nrbmApiHelper.sendReadMessage('\u003cvar fieldlabel=\"Phone number\" translate=\"no\"\u003e+12223334444\u003c/var\u003e', messageId);\n```\nThis code is an excerpt from an [RBM sample agent](/business-communications/rcs-business-messaging/samples).\n\n### Java\n\n```java\nimport com.google.rbm.RbmApiHelper;\n...\n\n// Create an instance of the RBM API helper\nRbmApiHelper rbmApiHelper = new RbmApiHelper();\n\n// Send the device an event to indicate that messageId has been read\nrbmApiHelper.sendReadMessage(messageId, \"\u003cvar fieldlabel=\"Phone number\" translate=\"no\"\u003e+12223334444\u003c/var\u003e\");\n```\nThis code is an excerpt from an [RBM sample agent](/business-communications/rcs-business-messaging/samples).\n\n### Python\n\n```python\n# Reference to RBM Python client helper and messaging object structure\nfrom rcs_business_messaging import rbm_service\n\n# Send the device an event to indicate that message_id was read\nrbm_service.send_read_event('\u003cvar fieldlabel=\"Phone number\" translate=\"no\"\u003e+12223334444\u003c/var\u003e', message_id)\n```\nThis code is an excerpt from an [RBM sample agent](/business-communications/rcs-business-messaging/samples).\n\n### C#\n\n```c#\nusing RCSBusinessMessaging;\n...\n\n// Create an instance of the RBM API helper\nRbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation,\n projectId);\n\n// Send the device an event to indicate that messageId has been read\nrbmApiHelper.SendReadMessage(messageId, \"\u003cvar fieldlabel=\"Phone number\" translate=\"no\"\u003e+12223334444\u003c/var\u003e\");\n```\nThis code is an excerpt from an [RBM sample agent](/business-communications/rcs-business-messaging/samples).\n\nTyping events\n-------------\n\n[Typing events](/business-communications/rcs-business-messaging/guides/build/events#typing)\nlet the user know that your agent is composing a message. The following code\nsends a typing event to a device with a client library. \n\n### Node.js\n\n```javascript\n// Reference to RBM API helper\nconst rbmApiHelper = require('@google/rcsbusinessmessaging');\n\n// Send the device an event to indicate that the agent is typing\nrbmApiHelper.sendIsTypingMessage('\u003cvar fieldlabel=\"Phone number\" translate=\"no\"\u003e+12223334444\u003c/var\u003e', function() {\n console.log('Typing event sent!');\n});\n```\nThis code is an excerpt from an [RBM sample agent](/business-communications/rcs-business-messaging/samples).\n\n### Java\n\n```java\nimport com.google.rbm.RbmApiHelper;\n...\n\n// Create an instance of the RBM API helper\nRbmApiHelper rbmApiHelper = new RbmApiHelper();\n\n// Send the device an event to indicate that the agent is typing\nrbmApiHelper.sendIsTypingMessage(\"\u003cvar fieldlabel=\"Phone number\" translate=\"no\"\u003e+12223334444\u003c/var\u003e\");\n```\nThis code is an excerpt from an [RBM sample agent](/business-communications/rcs-business-messaging/samples).\n\n### Python\n\n```python\n# Reference to RBM Python client helper and messaging object structure\nfrom rcs_business_messaging import rbm_service\n\n# Send the device an event to indicate that the agent is typing\nrbm_service.send_is_typing_event('\u003cvar fieldlabel=\"Phone number\" translate=\"no\"\u003e+12223334444\u003c/var\u003e')\n```\nThis code is an excerpt from an [RBM sample agent](/business-communications/rcs-business-messaging/samples).\n\n### C#\n\n```c#\nusing RCSBusinessMessaging;\n...\n\n// Create an instance of the RBM API helper\nRbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation,\n projectId);\n\n// Send the device an event to indicate that the agent is typing\nrbmApiHelper.SendIsTypingMessage(messageId, \"\u003cvar fieldlabel=\"Phone number\" translate=\"no\"\u003e+12223334444\u003c/var\u003e\");\n```\nThis code is an excerpt from an [RBM sample agent](/business-communications/rcs-business-messaging/samples)."]]