กิจกรรม

ในตัวอย่างต่อไปนี้ rbm_api_helper.js (ไม่ได้ใช้กับ Python) จะถือว่าไฟล์ที่คุณกำลังทำงานอยู่เป็นไดเรกทอรีที่อยู่ต่ำกว่าโฟลเดอร์แอปหลัก 1 ระดับ คุณอาจต้องปรับตำแหน่งตามการกำหนดค่าของโปรเจ็กต์

อ่านเหตุการณ์

เหตุการณ์อ่าน จะแจ้งให้ผู้ใช้ทราบว่าตัวแทนได้รับข้อความแล้ว และ สร้างความมั่นใจว่าแพลตฟอร์ม RCS for Business ได้ส่งข้อความของผู้ใช้แล้ว โค้ดต่อไปนี้จะส่งเหตุการณ์อ่านไปยังอุปกรณ์ที่มีไลบรารีของไคลเอ็นต์

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