ارسال پیام

عوامل RBM با ارسال و دریافت پیام با کاربران ارتباط برقرار می کنند. برای ارسال پیام به کاربران، نماینده شما درخواست‌های پیام را به RCS Business Messaging API ارسال می‌کند. یک درخواست می‌تواند شامل متن، کارت غنی، تصویر یا ویدیو و همچنین پاسخ‌های پیشنهادی و اقدامات پیشنهادی باشد.

اگر به کاربری که دستگاهش از RCS پشتیبانی نمی‌کند یا RCS را فعال نمی‌کند پیامی ارسال کنید، پلتفرم RBM خطای 404 را برمی‌گرداند. در این صورت می‌توانید از طریق روش‌های بازگشتی تعریف‌شده در زیرساخت خود، سعی کنید به کاربر دسترسی پیدا کنید.

اگر به یک کاربر RCS در شبکه‌ای که عامل شما هنوز راه‌اندازی نشده است، یا در شبکه‌ای که ترافیک RCS را فعال نکرده است، پیام ارسال کنید، پلتفرم RBM خطای 403 را برمی‌گرداند.

اگر پیامی با ویژگی‌هایی ارسال کنید که دستگاه کاربر از آن پشتیبانی نمی‌کند، پلتفرم RBM خطایی را برمی‌گرداند و پیام شما را تحویل نمی‌دهد.

حداکثر اندازه کل AgentMessage رشته ای 250 کیلوبایت است.

ارسال به یک کاربر آفلاین

اگر گیرنده آفلاین باشد، پلتفرم RBM همچنان پیامی را برای تحویل می‌پذیرد. شما یک پاسخ 200 OK دریافت می‌کنید و پلتفرم RBM پیام را نگه می‌دارد و به مدت 30 روز برای تحویل مجدد تلاش می‌کند. نیازی به درخواست RBM برای ارسال مجدد پیام نیست.

RBM 30 روز پس از ارسال پیام‌های تحویل‌نگرفته را حذف می‌کند.

بسته به مورد استفاده نماینده خود، ممکن است بخواهید قبل از این مهلت زمانی 30 روزه ، پیام تحویل‌نشده را لغو کنید . لغو می‌تواند از دریافت پیام قدیمی توسط کاربران آفلاین هنگام بازگشت به اینترنت جلوگیری کند. چندین راه برای لغو یک پیام وجود دارد:

انقضای پیام را تنظیم کنید

آیا زمان پیام نماینده شما حساس است؟ به عنوان مثال، OTP ها فقط برای یک دوره کوتاه معتبر هستند. پیشنهادات با زمان محدود منقضی می شود. و یادآوری‌های قرار بعد از تاریخ قرار دیگر مرتبط نیستند. برای کمک به اطمینان از ارسال به موقع و مرتبط، انقضای پیام را تنظیم کنید. این می تواند از دریافت محتوای قدیمی کاربران آفلاین در هنگام بازگشت به اینترنت جلوگیری کند. انقضا همچنین نشانه خوبی برای استفاده از استراتژی پیام‌رسانی مجدد است تا کاربران اطلاعات مورد نیاز خود را به موقع دریافت کنند.

برای تنظیم انقضای پیام، یکی از فیلدهای زیر را در پیام عامل مشخص کنید:

  • expireTime : زمان دقیق در UTC زمانی که پیام منقضی می شود.
  • ttl (زمان برای زندگی): مدت زمان قبل از انقضای پیام.

برای گزینه‌های قالب‌بندی و مقدار، AgentMessage را ببینید.

هنگامی که پیام منقضی می شود، پلت فرم RBM تلاش برای ارائه پیام را متوقف می کند و به طور خودکار لغو می شود. با این حال، این ممکن است در موارد نادر شکست بخورد. برای مثال، API می‌تواند لغو را در زمانی که پلتفرم RBM در حال تحویل پیام است، راه‌اندازی کند. برای تأیید اینکه آیا پیام منقضی شده با موفقیت ابطال شده است یا خیر، RBM یک رویداد اعلان به وب هوک شما ارسال می کند.

متن

ساده ترین پیام ها از متن ساخته شده اند. پیام‌های متنی برای انتقال اطلاعات بدون نیاز به تصاویر بصری، تعامل پیچیده یا پاسخ مناسب هستند.

مثال

کد زیر یک پیام متنی ساده ارسال می کند. برای گزینه‌های قالب‌بندی و مقدار، به phones.agentMessages.create مراجعه کنید.

حلقه

curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_ID&agentId=AGENT_ID" \
-H "Content-Type: application/json" \
-H "User-Agent: curl/rcs-business-messaging" \
-H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \
-d "{
  'contentMessage': {
    'text': 'Hello, world!'
  }
}"

Node.js

// Reference to RBM API helper
const rbmApiHelper = require('@google/rcsbusinessmessaging');

let params = {
   messageText: 'Hello, world!',
   msisdn: '+12223334444',
};

// Send a simple message to the device
rbmApiHelper.sendMessage(params, function(response) {
   console.log(response);
});
این کد گزیده ای از یک عامل نمونه RBM است.

جاوا

import com.google.rbm.RbmApiHelper;
…

try {
   // Create an instance of the RBM API helper
   RbmApiHelper rbmApiHelper = new RbmApiHelper();

   // Send simple text message to user
   rbmApiHelper.sendTextMessage(
      "Hello, world!",
      "+12223334444"
   );
} catch(Exception e) {
   e.printStackTrace();
}
این کد گزیده ای از یک عامل نمونه RBM است.

پایتون

# Reference to RBM Python client helper and messaging object structure
from rcs_business_messaging import rbm_service
from rcs_business_messaging import messages

# Create a simple RBM text message
message_text = messages.TextMessage('Hello, world!')

# Send text message to the device
messages.MessageCluster().append_message(message_text).send_to_msisdn('+12223334444')
این کد گزیده ای از یک عامل نمونه RBM است.

سی شارپ

using RCSBusinessMessaging;
…

// Create an instance of the RBM API helper
RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation,
                                             projectId);

rbmApiHelper.SendTextMessage(
    "Hello, world!",
    "+12223334444",
);
این کد گزیده ای از یک عامل نمونه RBM است.

محتوای پیام اصلی - تبدیل پیامک

اپراتورها مدل های صورتحساب را برای پشتیبانی از انتقال پیامک به RBM معرفی کرده اند. پیام RBM حاوی حداکثر 160 کاراکتر UTF-8، پیام اصلی نامیده می شود.

هنگام ساخت یک درخواست برای ارسال یک پیام اصلی، به یاد داشته باشید که کاراکترها به عنوان 1 بایت (UTF-8) شمارش می شوند. اگر پیامی حاوی کاراکترهای خاص مانند ایموجی یا مجموعه کاراکترهای چند بایتی ارسال کنید، هر کاراکتر به عنوان 2 کاراکتر UTF-8 محاسبه می شود.

مقداری متن را در کادر وارد کنید تا طول آن را بررسی کنید:

رمزهای عبور یکبار مصرف برای تأیید کاربر

می‌توانید از RBM برای ارسال رمزهای عبور یک‌بار مصرف (OTP) برای تأیید خودکار کاربر با SMS Retriever API استفاده کنید. برای کسب اطلاعات بیشتر در مورد SMS Retriever و APIهای مرتبط، به مستندات SMS Retriever مراجعه کنید. برای جزئیات درباره تأیید خودکار کاربر در برنامه‌هایی که با SMS Retriever API ثبت‌نام کرده‌اند، این نمودار جریان را ببینید.

در طول فرآیند تأیید، API SMS Retriever به پیام RBM گوش می دهد. این پیام باید حاوی یک OTP و یک هش باشد که برنامه را شناسایی کند. پس از تطبیق هش با برنامه، OTP استخراج شده و برای تأیید خودکار کاربر به برنامه ارسال می شود.

در اینجا یک نمونه پیام متنی RBM برای تأیید کاربر آمده است: کد شما <OTP> <app hash> است.

به عنوان مثال، Your code is 123456 M8tue43FGT.

فایل های رسانه ای و پی دی اف

وقتی پیامی با تصویر، ویدیو یا فایل PDF ارسال می‌کنید، نماینده شما باید یک URL در دسترس عموم برای محتوا ارائه کند یا فایل را مستقیماً آپلود کند. برای فایل‌های رسانه‌ای، می‌توانید یک تصویر کوچک نیز مشخص کنید که به کاربران اجازه می‌دهد پیش‌نمایش محتوا را قبل از کلیک بر روی آن مشاهده کنند.

پلتفرم RBM فایل‌ها را به مدت 60 روز در حافظه پنهان نگه می‌دارد و API شناسه فایلی را که نماینده شما می‌تواند در پیام‌ها به کاربران اضافه کند، برمی‌گرداند. پس از 60 روز، RBM فایل ها را از حافظه پنهان حذف می کند.

بهترین روش‌ها را برای توصیه‌ها و محدودیت‌های اندازه فایل مشاهده کنید.

نمونه URL فایل

کد زیر یک تصویر را ارسال می کند. برای گزینه های قالب بندی و مقدار، AgentContentMessage را ببینید.

حلقه

curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_ID&agentId=AGENT_ID" \
-H "Content-Type: application/json" \
-H "User-Agent: curl/rcs-business-messaging" \
-H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \
-d "{
  'contentMessage': {
    'contentInfo': {
      'fileUrl': 'http://www.google.com/logos/doodles/2015/googles-new-logo-5078286822539264.3-hp2x.gif',
      'forceRefresh': 'false'
    }
  }
}"

Node.js

// Reference to RBM API helper
const rbmApiHelper = require('@google/rcsbusinessmessaging');

let params = {
   fileUrl: 'http://www.google.com/logos/doodles/2015/googles-new-logo-5078286822539264.3-hp2x.gif',
   msisdn: '+12223334444',
};

// Send an image/video to a device
rbmApiHelper.sendMessage(params, function(response) {
   console.log(response);
});
این کد گزیده ای از یک عامل نمونه RBM است.

جاوا

import com.google.api.services.rcsbusinessmessaging.v1.model.AgentContentMessage;
import com.google.api.services.rcsbusinessmessaging.v1.model.AgentMessage;
import com.google.rbm.RbmApiHelper;
…

try {
   // Create an instance of the RBM API helper
   RbmApiHelper rbmApiHelper = new RbmApiHelper();

   String fileUrl = "http://www.google.com/logos/doodles/2015/googles-new-logo-5078286822539264.3-hp2x.gif";

   // create media only message
   AgentContentMessage agentContentMessage = new AgentContentMessage();
   agentContentMessage.setContentInfo(new ContentInfo().setFileUrl(fileUrl));

   // attach content to message
   AgentMessage agentMessage = new AgentMessage();
   agentMessage.setContentMessage(agentContentMessage);

   rbmApiHelper.sendAgentMessage(agentMessage, "+12223334444");
} catch(Exception e) {
   e.printStackTrace();
}
این کد گزیده ای از یک عامل نمونه RBM است.

پایتون

# Reference to RBM Python client helper and messaging object structure
from rcs_business_messaging import rbm_service
from rcs_business_messaging import messages

# Create media file attachment
file_message = messages.FileMessage('http://www.google.com/logos/doodles/2015/googles-new-logo-5078286822539264.3-hp2x.gif')

messages.MessageCluster().append_message(file_message).send_to_msisdn('+12223334444')
این کد گزیده ای از یک عامل نمونه RBM است.

سی شارپ

using Google.Apis.RCSBusinessMessaging.v1.Data;
using RCSBusinessMessaging;
…

// Create an instance of the RBM API helper
RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation,
                                                 projectId);

string fileUrl = "http://www.google.com/logos/doodles/2015/googles-new-logo-5078286822539264.3-hp2x.gif";

// Create content info with the file url
ContentInfo contentInfo = new ContentInfo
{
    FileUrl = fileUrl
};

// Attach content info to a message
AgentContentMessage agentContentMessage = new AgentContentMessage
{
    ContentInfo = contentInfo,
};

// Attach content to message
AgentMessage agentMessage = new AgentMessage
{
    ContentMessage = agentContentMessage
};

rbmApiHelper.SendAgentMessage(agentMessage, "+12223334444");
این کد گزیده ای از یک عامل نمونه RBM است.

از طرف دیگر، می‌توانید قبل از ارسال رسانه در پیامی با files.create آن را آپلود کنید.

نمونه آپلود فایل

کد زیر یک فایل ویدئویی و یک فایل تصویر کوچک را آپلود می کند، سپس هر دو فایل را در یک پیام ارسال می کند. برای گزینه‌های قالب‌بندی و مقدار، به files.create و AgentContentMessage مراجعه کنید.

حلقه

curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/upload/v1/files?agentId=AGENT_ID" \
-H "Content-Type: video/mp4" \
-H "User-Agent: curl/rcs-business-messaging" \
-H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \
--upload-file "FULL_PATH_TO_VIDEO_MEDIA_FILE"

# Capture server-specified video file name from response body JSON


curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/upload/v1/files?agentId=AGENT_ID" \
-H "Content-Type: image/jpeg" \
-H "User-Agent: curl/rcs-business-messaging" \
-H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \
--upload-file "FULL_PATH_TO_THUMBNAIL_MEDIA_FILE"

# Capture server-specified image file name from response body JSON


curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_ID&agentId=AGENT_ID" \
-H "Content-Type: application/json" \
-H "User-Agent: curl/rcs-business-messaging" \
-H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \
-d "{
  'contentMessage': {
    'uploadedRbmFile': {
      'fileName': 'SERVER-SPECIFIED_VIDEO_FILE_NAME'
        'thumbnailName': 'SERVER-SPECIFIED_THUMBNAIL_FILE_NAME'
   }
  }
}"

انواع رسانه های پشتیبانی شده

RBM انواع رسانه های زیر را پشتیبانی می کند:

نوع رسانه نوع سند افزونه با کارت های غنی کار می کند
اپلیکیشن/pdf PDF .pdf خیر
تصویر/jpeg JPEG jpeg، .jpg آره
تصویر/گیف GIF .gif آره
تصویر/png PNG .png آره
ویدیو/h263 ویدیوی H263 .h263 آره
ویدئو/m4v ویدئوی M4V m4v آره
ویدئو/mp4 ویدیو MP4 mp4 آره
ویدئو/mpeg4 ویدئو MPEG-4 mp4، .m4p آره
ویدئو/MPEG ویدئو MPEG mpeg آره
ویدئو/وب ویدئو WEBM .webm آره

پاسخ های پیشنهادی

پاسخ‌های پیشنهادی با ارائه پاسخ‌هایی که نماینده شما می‌داند چگونه به آن‌ها واکنش نشان دهد، کاربران را در گفتگوها راهنمایی می‌کند. نماینده شما پاسخ‌های پیشنهادی را در فهرست‌های تراشه پیشنهادی یا کارت‌های غنی ارسال می‌کند.

هنگامی که کاربر روی یک پاسخ پیشنهادی ضربه می‌زند، نماینده شما رویدادی را دریافت می‌کند که حاوی متن پاسخ و داده‌های بازپس‌گیری است.

پاسخ های پیشنهادی حداکثر 25 کاراکتر دارند.

مثال

کد زیر متنی را با دو پاسخ پیشنهادی ارسال می کند. برای گزینه‌های قالب‌بندی و مقدار، به SuggestedReply مراجعه کنید.

حلقه

curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_ID&agentId=AGENT_ID" \
-H "Content-Type: application/json" \
-H "User-Agent: curl/rcs-business-messaging" \
-H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \
-d "{
  'contentMessage': {
    'text': 'Hello, world!',
    'suggestions': [
      {
        'reply': {
          'text': 'Suggestion #1',
          'postbackData': 'suggestion_1'
        }
      },
      {
        'reply': {
          'text': 'Suggestion #2',
          'postbackData': 'suggestion_2'
        }
      }
    ]
  }
}"

Node.js

// Reference to RBM API helper
const rbmApiHelper = require('@google/rcsbusinessmessaging');

let suggestions = [
   {
      reply: {
         'text': 'Suggestion #1',
         'postbackData': 'suggestion_1',
      },
   },
   {
      reply: {
         'text': 'Suggestion #2',
         'postbackData': 'suggestion_2',
      },
   },
];

let params = {
   messageText: 'Hello, world!',
   msisdn: '+12223334444',
   suggestions: suggestions,
};

// Send a simple message with suggestion chips to the device
rbmApiHelper.sendMessage(params, function(response) {
   console.log(response);
});
این کد گزیده ای از یک عامل نمونه RBM است.

جاوا

import com.google.api.services.rcsbusinessmessaging.v1.model.Suggestion;
import com.google.rbm.RbmApiHelper;
import com.google.rbm.SuggestionHelper;
…

try {
   // Create an instance of the RBM API helper
   RbmApiHelper rbmApiHelper = new RbmApiHelper();

   // Create suggestions for chip list
   List<Suggestion> suggestions = new ArrayList<Suggestion>();
   suggestions.add(
      new SuggestionHelper("Suggestion #1", "suggestion_1").getSuggestedReply());

   suggestions.add(
      new SuggestionHelper("Suggestion #2", "suggestion_2").getSuggestedReply());

   // Send simple text message to user
   rbmApiHelper.sendTextMessage(
      "Hello, world!",
      "+12223334444",
      suggestions
   );
} catch(Exception e) {
   e.printStackTrace();
}
این کد گزیده ای از یک عامل نمونه RBM است.

پایتون

# Reference to RBM Python client helper and messaging object structure
from rcs_business_messaging import rbm_service
from rcs_business_messaging import messages

# Create text message to send to user
text_msg = messages.TextMessage('Hello, world!')
cluster = messages.MessageCluster().append_message(text_msg)

# Append suggested replies for the message to send to the user
cluster.append_suggestion_chip(messages.SuggestedReply('Suggestion #1', 'reply:suggestion_1'))
cluster.append_suggestion_chip(messages.SuggestedReply('Suggestion #2', 'reply:suggestion_2'))

# Send a simple message with suggestion chips to the device
cluster.send_to_msisdn('+12223334444')
این کد گزیده ای از یک عامل نمونه RBM است.

سی شارپ

using Google.Apis.RCSBusinessMessaging.v1.Data;
using RCSBusinessMessaging;
…

// Create an instance of the RBM API helper
RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation,
                                             projectId);

List<Suggestion> suggestions = new List<Suggestion>
{
   // Create suggestion chips
   new SuggestionHelper("Suggestion #1", "suggestion_1").SuggestedReply(),
   new SuggestionHelper("Suggestion #2", "suggestion_2").SuggestedReply()
};

// Send simple text message with suggestions to user
rbmApiHelper.SendTextMessage(
    "Hello, world!",
    "+12223334444",
   suggestions
);
این کد گزیده ای از یک عامل نمونه RBM است.

اقدامات پیشنهاد شده

کنش‌های پیشنهادی با کنار گذاشتن عملکرد بومی دستگاه‌هایشان، کاربران را از طریق مکالمات راهنمایی می‌کند. نماینده شما می‌تواند به کاربران پیشنهاد کند شماره‌ای را شماره‌گیری کنند، یک مکان را روی نقشه باز کنند، یک مکان را به اشتراک بگذارند، یک URL باز کنند یا یک رویداد تقویم ایجاد کنند. نماینده شما اقدامات پیشنهادی را در لیست های تراشه پیشنهادی یا کارت های غنی ارسال می کند.

وقتی کاربر روی یک کنش پیشنهادی ضربه می‌زند، نماینده شما رویدادی را دریافت می‌کند که حاوی داده‌های پس‌بازگشت کنش است.

اقدامات پیشنهادی حداکثر 25 کاراکتر دارند.

برای گزینه‌های قالب‌بندی و مقدار، به SuggestedAction مراجعه کنید.

یک شماره بگیرید

عمل شماره گیری کاربر را راهنمایی می کند تا شماره تلفنی را که نماینده شما مشخص کرده است شماره گیری کند. شماره تلفن‌ها باید دارای علامت + اصلی، کد کشور و کد منطقه باشند، اما نباید دارای جداکننده باشند. به عنوان مثال، +14155555555 .

مثال

کد زیر یک عمل شماره گیری را ارسال می کند. برای گزینه‌های قالب‌بندی و مقدار، به DialAction مراجعه کنید.

حلقه

curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_ID&agentId=AGENT_ID" \
-H "Content-Type: application/json" \
-H "User-Agent: curl/rcs-business-messaging" \
-H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \
-d "{
  'contentMessage': {
    'text': 'Hello, world!',
    'suggestions': [
      {
        'action': {
          'text': 'Call',
          'postbackData': 'postback_data_1234',
          'fallbackUrl': 'https://www.google.com/contact/',
          'dialAction': {
            'phoneNumber': '+15556667777'
          }
        }
      }
    ]
  }
}"

Node.js

// Reference to RBM API helper
const rbmApiHelper = require('@google/rcsbusinessmessaging');

// Define a dial suggested action
let suggestions = [
   {
      action: {
         text: 'Call',
         postbackData: 'postback_data_1234',
         dialAction: {
            phoneNumber: '+15556667777'
         }
      }
   },
];

let params = {
   messageText: 'Hello, world!',
   msisdn: '+12223334444',
   suggestions: suggestions,
};

// Send a simple message with a dial suggested action
rbmApiHelper.sendMessage(params, function(response) {
   console.log(response);
});
این کد گزیده ای از یک عامل نمونه RBM است.

جاوا

import com.google.api.services.rcsbusinessmessaging.v1.model.DialAction;
import com.google.api.services.rcsbusinessmessaging.v1.model.SuggestedAction;
import com.google.api.services.rcsbusinessmessaging.v1.model.Suggestion;
import com.google.rbm.RbmApiHelper;
…

try {
   // Create an instance of the RBM API helper
   RbmApiHelper rbmApiHelper = new RbmApiHelper();

   // Create suggestions for chip list
   List<Suggestion> suggestions = new ArrayList<Suggestion>();

   // creating a dial suggested action
   DialAction dialAction = new DialAction();
   dialAction.setPhoneNumber("+15556667777");

   // creating a suggested action based on a dial action
   SuggestedAction suggestedAction = new SuggestedAction();
   suggestedAction.setText("Call");
   suggestedAction.setPostbackData("postback_data_1234");
   suggestedAction.setDialAction(dialAction);

   // attaching action to a suggestion
   Suggestion suggestion = new Suggestion();
   suggestion.setAction(suggestedAction);

   suggestions.add(suggestion);

   // Send simple text message with the suggestion action
   rbmApiHelper.sendTextMessage(
      "Hello, world!",
      "+12223334444",
      suggestions
   );
} catch(Exception e) {
   e.printStackTrace();
}
این کد گزیده ای از یک عامل نمونه RBM است.

پایتون

# Reference to RBM Python client helper and messaging object structure
from rcs_business_messaging import rbm_service
from rcs_business_messaging import messages

# Create a dial suggested action
suggestions = [
      messages.DialAction('Call', 'reply:postback_data_1234', '+15556667777')
]

# Create text message to send to user
text_msg = messages.TextMessage('Hello, world!')
cluster = messages.MessageCluster().append_message(text_msg)

# Append suggestions for the message to send to the user
for suggestion in suggestions:
    cluster.append_suggestion_chip(suggestion)

# Send a simple message with suggested action to the device
cluster.send_to_msisdn('+12223334444')
این کد گزیده ای از یک عامل نمونه RBM است.

سی شارپ

using Google.Apis.RCSBusinessMessaging.v1.Data;
using RCSBusinessMessaging;
…

// Create an instance of the RBM API helper
RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation,
                                                 projectId);

// Create a dial an agent suggested action
DialAction dialAction = new DialAction
{
    PhoneNumber = "+15556667777"
};

// Creating a suggested action based on a dial action
SuggestedAction suggestedAction = new SuggestedAction
{
    Text = "Call",
    PostbackData = "postback_data_1234",
    DialAction = dialAction
};

// Attach action to a suggestion
Suggestion suggestion = new Suggestion
{
    Action = suggestedAction
};

List<Suggestion> suggestions = new List<Suggestion>
{
    suggestion
};

rbmApiHelper.SendTextMessage(
    "Hello, world!",
    "+12223334444",
    suggestions
);
این کد گزیده ای از یک عامل نمونه RBM است.

یک مکان را مشاهده کنید

عملکرد View location یک مکان را در برنامه نقشه پیش فرض کاربر نشان می دهد. شما می توانید مکان را بر اساس طول و عرض جغرافیایی یا با پرس و جو بر اساس مکان فعلی کاربر مشخص کنید. همچنین می توانید یک برچسب سفارشی برای پینی که در برنامه نقشه نمایش داده می شود تنظیم کنید.

مثال

کد زیر یک عملکرد مکان نمایش را ارسال می کند. برای گزینه‌های قالب‌بندی و مقدار، ViewLocationAction را ببینید.

حلقه

curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_ID&agentId=AGENT_ID" \
-H "Content-Type: application/json" \
-H "User-Agent: curl/rcs-business-messaging" \
-H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \
-d "{
  'contentMessage': {
    'text': 'Hello, world!',
    'suggestions': [
      {
        'action': {
          'text': 'View map',
          'postbackData': 'postback_data_1234',
          'fallbackUrl': 'https://www.google.com/maps/@37.4220188,-122.0844786,15z',
          'viewLocationAction': {
            'latLong': {
              'latitude': "37.4220188',
              'longitude': "-122.0844786'
            },
            'label': 'Googleplex'
          }
        }
      }
    ]
  }
}"

Node.js

// Reference to RBM API helper
const rbmApiHelper = require('@google/rcsbusinessmessaging');

// Define a view location suggested action
let suggestions = [
   {
      action: {
         text: 'View map',
         postbackData: 'postback_data_1234',
         viewLocationAction: {
            latLong: {
               latitude: 37.4220188,
               longitude: -122.0844786
            },
            label: 'Googleplex'
         }
      }
   },
];

let params = {
   messageText: 'Hello, world!',
   msisdn: '+12223334444',
   suggestions: suggestions,
};

// Send a simple message with a view location suggested action
rbmApiHelper.sendMessage(params, function(response) {
   console.log(response);
});
این کد گزیده ای از یک عامل نمونه RBM است.

جاوا

import com.google.api.services.rcsbusinessmessaging.v1.model.ViewLocationAction;
import com.google.api.services.rcsbusinessmessaging.v1.model.SuggestedAction;
import com.google.api.services.rcsbusinessmessaging.v1.model.Suggestion;
import com.google.rbm.RbmApiHelper;
…

try {
   // Create an instance of the RBM API helper
   RbmApiHelper rbmApiHelper = new RbmApiHelper();

   // Create suggestions for chip list
   List<Suggestion> suggestions = new ArrayList<Suggestion>();

   // creating a view location suggested action
   ViewLocationAction viewLocationAction = new ViewLocationAction();
   viewLocationAction.setQuery("Googleplex, Mountain View, CA");

   // creating a suggested action based on a view location action
   SuggestedAction suggestedAction = new SuggestedAction();
   suggestedAction.setText("View map");
   suggestedAction.setPostbackData("postback_data_1234");
   suggestedAction.setViewLocationAction(viewLocationAction);

   // attaching action to a suggestion
   Suggestion suggestion = new Suggestion();
   suggestion.setAction(suggestedAction);

   suggestions.add(suggestion);

   // Send simple text message with the suggestion action
   rbmApiHelper.sendTextMessage(
      "Hello, world!",
      "+12223334444",
      suggestions
   );
} catch(Exception e) {
   e.printStackTrace();
}
این کد گزیده ای از یک عامل نمونه RBM است.

پایتون

# Reference to RBM Python client helper and messaging object structure
from rcs_business_messaging import rbm_service
from rcs_business_messaging import messages

# Create a view location suggested action
suggestions = [
      messages.ViewLocationAction('View map',
            'reply:postback_data_1234',
            query='Googleplex, Mountain View, CA')
]

# Create text message to send to user
text_msg = messages.TextMessage('Hello, world!')
cluster = messages.MessageCluster().append_message(text_msg)

# Append suggestions for the message to send to the user
for suggestion in suggestions:
    cluster.append_suggestion_chip(suggestion)

# Send a simple message with suggested action to the device
cluster.send_to_msisdn('+12223334444')
این کد گزیده ای از یک عامل نمونه RBM است.

سی شارپ

using Google.Apis.RCSBusinessMessaging.v1.Data;
using RCSBusinessMessaging;
…

// Create an instance of the RBM API helper
RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation,
                                                 projectId);

// create an view location action
ViewLocationAction viewLocationAction = new ViewLocationAction
{
    Query = "Googleplex Mountain View, CA"
};

// Attach the view location action to a suggested action
SuggestedAction suggestedAction = new SuggestedAction
{
    ViewLocationAction = viewLocationAction,
    Text = "View map",
    PostbackData = "postback_data_1234"
};

// Attach the action to a suggestion object
Suggestion suggestion = new Suggestion
{
    Action = suggestedAction
};

List<Suggestion> suggestions = new List<Suggestion>
{
    suggestion
};

rbmApiHelper.SendTextMessage(
    "Hello, world!",
    "+12223334444",
    suggestions
);
این کد گزیده ای از یک عامل نمونه RBM است.

مکان را به اشتراک بگذارید

عملکرد اشتراک‌گذاری موقعیت مکانی به کاربر امکان می‌دهد موقعیت مکانی را برای نماینده شما ارسال کند. مکانی که کاربر مشخص می کند لزوماً موقعیت مکانی کاربر نیست.

مثال

کد زیر یک اقدام مکان اشتراک گذاری را ارسال می کند. برای گزینه‌های قالب‌بندی و مقدار، ShareLocationAction را ببینید.

حلقه

curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_ID&agentId=AGENT_ID" \
-H "Content-Type: application/json" \
-H "User-Agent: curl/rcs-business-messaging" \
-H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \
-d "{
  'contentMessage': {
    'text': 'Hello, world!',
    'suggestions': [
      {
        'action': {
          'text': 'Share your location',
          'postbackData': 'postback_data_1234',
          'shareLocationAction': {}
        }
      }
    ]
  }
}"

Node.js

// Reference to RBM API helper
const rbmApiHelper = require('@google/rcsbusinessmessaging');

// Define a share location suggested action
let suggestions = [
   {
      action: {
         text: 'Share your location',
         postbackData: 'postback_data_1234',
         shareLocationAction: {
         }
      }
   },
];

let params = {
   messageText: 'Hello, world!',
   msisdn: '+12223334444',
   suggestions: suggestions,
};

// Send a simple message with a share location suggested action
rbmApiHelper.sendMessage(params, function(response) {
   console.log(response);
});
این کد گزیده ای از یک عامل نمونه RBM است.

جاوا

import com.google.api.services.rcsbusinessmessaging.v1.model.ShareLocationAction;
import com.google.api.services.rcsbusinessmessaging.v1.model.SuggestedAction;
import com.google.api.services.rcsbusinessmessaging.v1.model.Suggestion;
import com.google.rbm.RbmApiHelper;
…

try {
   // Create an instance of the RBM API helper
   RbmApiHelper rbmApiHelper = new RbmApiHelper();

   // Create suggestions for chip list
   List<Suggestion> suggestions = new ArrayList<Suggestion>();

   // creating a share location suggested action
   ShareLocationAction shareLocationAction = new ShareLocationAction();

   // creating a suggested action based on a share location action
   SuggestedAction suggestedAction = new SuggestedAction();
   suggestedAction.setText("Share location");
   suggestedAction.setPostbackData("postback_data_1234");
   suggestedAction.setShareLocationAction(shareLocationAction);

   // attaching action to a suggestion
   Suggestion suggestion = new Suggestion();
   suggestion.setAction(suggestedAction);

   suggestions.add(suggestion);

   // Send simple text message with the suggestion action
   rbmApiHelper.sendTextMessage(
      "Hello, world!",
      "+12223334444",
      suggestions
   );
} catch(Exception e) {
   e.printStackTrace();
}
این کد گزیده ای از یک عامل نمونه RBM است.

پایتون

# Reference to RBM Python client helper and messaging object structure
from rcs_business_messaging import rbm_service
from rcs_business_messaging import messages

# Create a share location suggested action
suggestions = [
      messages.ShareLocationAction('Share location',
            'reply:postback_data_1234')
]

# Create text message to send to user
text_msg = messages.TextMessage('Hello, world!')
cluster = messages.MessageCluster().append_message(text_msg)

# Append suggestions for the message to send to the user
for suggestion in suggestions:
    cluster.append_suggestion_chip(suggestion)

# Send a simple message with suggested action to the device
cluster.send_to_msisdn('+12223334444')
این کد گزیده ای از یک عامل نمونه RBM است.

سی شارپ

using Google.Apis.RCSBusinessMessaging.v1.Data;
using RCSBusinessMessaging;
…

// Create an instance of the RBM API helper
RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation,
                                                 projectId);

// Create a share location action
ShareLocationAction shareLocationAction = new ShareLocationAction();

// Attach the share location action to a suggested action
SuggestedAction suggestedAction = new SuggestedAction
{
    ShareLocationAction = shareLocationAction,
    Text = "Share location",
    PostbackData = "postback_data_1234"
};

// Attach the action to a suggestion object
Suggestion suggestion = new Suggestion
{
    Action = suggestedAction
};

List<Suggestion> suggestions = new List<Suggestion>
{
    suggestion
};

rbmApiHelper.SendTextMessage(
    "Hello, world!",
    "+12223334444",
    suggestions
);
این کد گزیده ای از یک عامل نمونه RBM است.

یک URL باز کنید

عمل Open URL مرورگر وب کاربر را به URL مشخص شده باز می کند. اگر برنامه‌ای به‌عنوان یک کنترل‌کننده پیش‌فرض برای URL ثبت شده باشد، برنامه به جای آن باز می‌شود و نماد عمل نماد برنامه است.

مثال

کد زیر یک اقدام URL باز ارسال می کند. برای گزینه‌های قالب‌بندی و مقدار، به OpenUrlAction مراجعه کنید.

حلقه

curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_ID&agentId=AGENT_ID" \
-H "Content-Type: application/json" \
-H "User-Agent: curl/rcs-business-messaging" \
-H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \
-d "{
  'contentMessage': {
    'text': 'Hello, world!',
    'suggestions': [
      {
        'action': {
          'text': 'Open Google',
          'postbackData': 'postback_data_1234',
          'openUrlAction': {
            'url': 'https://www.google.com'
          }
        }
      }
    ]
  }
}"

Node.js

// Reference to RBM API helper
const rbmApiHelper = require('@google/rcsbusinessmessaging');

// Define an open URL suggested action
let suggestions = [
   {
      action: {
         text: 'Open Google',
         postbackData: 'postback_data_1234',
         openUrlAction: {
            url: 'https://www.google.com'
         }
      }
   },
];

let params = {
   messageText: 'Hello, world!',
   msisdn: '+12223334444',
   suggestions: suggestions,
};

// Send a simple message with an open URL suggested action
rbmApiHelper.sendMessage(params, function(response) {
   console.log(response);
});
این کد گزیده ای از یک عامل نمونه RBM است.

جاوا


import com.google.api.services.rcsbusinessmessaging.v1.model.OpenUrlAction;
import com.google.api.services.rcsbusinessmessaging.v1.model.SuggestedAction;
import com.google.api.services.rcsbusinessmessaging.v1.model.Suggestion;
import com.google.rbm.RbmApiHelper;
…

try {
   // Create an instance of the RBM API helper
   RbmApiHelper rbmApiHelper = new RbmApiHelper();

   // Create suggestions for chip list
   List<Suggestion> suggestions = new ArrayList<Suggestion>();

   // creating an open url suggested action
   OpenUrlAction openUrlAction = new OpenUrlAction();
   openUrlAction.setUrl("https://www.google.com");

   // creating a suggested action based on an open url action
   SuggestedAction suggestedAction = new SuggestedAction();
   suggestedAction.setText("Open Google");
   suggestedAction.setPostbackData("postback_data_1234");
   suggestedAction.setOpenUrlAction(openUrlAction);

   // attaching action to a suggestion
   Suggestion suggestion = new Suggestion();
   suggestion.setAction(suggestedAction);

   suggestions.add(suggestion);

   // Send simple text message with the suggestion action
   rbmApiHelper.sendTextMessage(
      "Hello, world!",
      "+12223334444",
      suggestions
   );
} catch(Exception e) {
   e.printStackTrace();
}
این کد گزیده ای از یک عامل نمونه RBM است.

پایتون

# Reference to RBM Python client helper and messaging object structure
from rcs_business_messaging import rbm_service
from rcs_business_messaging import messages

# Create an open url suggested action
suggestions = [
      messages.OpenUrlAction('Open Google',
            'reply:postback_data_1234',
            'https://www.google.com')
]

# Create text message to send to user
text_msg = messages.TextMessage('Hello, world!')
cluster = messages.MessageCluster().append_message(text_msg)

# Append suggestions for the message to send to the user
for suggestion in suggestions:
    cluster.append_suggestion_chip(suggestion)

# Send a simple message with suggested action to the device
cluster.send_to_msisdn('+12223334444')
این کد گزیده ای از یک عامل نمونه RBM است.

سی شارپ

using Google.Apis.RCSBusinessMessaging.v1.Data;
using RCSBusinessMessaging;
…

// Create an instance of the RBM API helper
RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation,
                                                 projectId);

// Create an open url action
OpenUrlAction openUrlAction = new OpenUrlAction
{
    Url = "https://www.google.com"
};

// Attach the open url action to a suggested action
SuggestedAction suggestedAction = new SuggestedAction
{
    OpenUrlAction = openUrlAction,
    Text = "Open Google",
    PostbackData = "postback_data_1234"
};

// Attach the action to a suggestion object
Suggestion suggestion = new Suggestion
{
    Action = suggestedAction
};

List<Suggestion> suggestions = new List<Suggestion>
{
    suggestion
};

rbmApiHelper.SendTextMessage(
    "Hello, world!",
    "+12223334444",
    suggestions
);
این کد گزیده ای از یک عامل نمونه RBM است.

یک رویداد تقویم ایجاد کنید

عمل ایجاد رویداد تقویم، برنامه تقویم کاربر را باز می کند و شروع به ایجاد یک رویداد جدید با اطلاعات مشخص شده می کند.

مثال

کد زیر یک اقدام رویداد ایجاد تقویم را ارسال می کند. برای گزینه‌های قالب‌بندی و مقدار، به CreateCalendarEventAction مراجعه کنید.

حلقه

curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_ID&agentId=AGENT_ID" \
-H "Content-Type: application/json" \
-H "User-Agent: curl/rcs-business-messaging" \
-H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \
-d "{
  'contentMessage': {
    'text': 'Hello, world!',
    'suggestions': [
      {
        'action': {
          'text': 'Save to calendar',
          'postbackData': 'postback_data_1234',
          'fallbackUrl': 'https://www.google.com/calendar',
          'createCalendarEventAction': {
            'startTime': '2020-06-30T19:00:00Z',
            'endTime': '2020-06-30T20:00:00Z',
            'title': 'My calendar event',
            'description': 'Description of the calendar event'
          }
        }
      }
    ]
  }
}"

Node.js

// Reference to RBM API helper
const rbmApiHelper = require('@google/rcsbusinessmessaging');

// Define a create calendar event suggested action
let suggestions = [
   {
      action: {
         text: 'Save to calendar',
         postbackData: 'postback_data_1234',
         createCalendarEventAction: {
            startTime: '2020-06-30T19:00:00Z',
            endTime: '2020-06-30T20:00:00Z',
            title: 'My calendar event',
            description: 'Description of the calendar event',
         },
      }
   },
];

let params = {
   messageText: 'Hello, world!',
   msisdn: '+12223334444',
   suggestions: suggestions,
};

// Send a simple message with a create calendar event suggested action
rbmApiHelper.sendMessage(params, function(response) {
   console.log(response);
});
این کد گزیده ای از یک عامل نمونه RBM است.

جاوا


import com.google.api.services.rcsbusinessmessaging.v1.model.CreateCalendarEventAction;
import com.google.api.services.rcsbusinessmessaging.v1.model.SuggestedAction;
import com.google.api.services.rcsbusinessmessaging.v1.model.Suggestion;
import com.google.rbm.RbmApiHelper;
…

try {
   // Create an instance of the RBM API helper
   RbmApiHelper rbmApiHelper = new RbmApiHelper();

   // Create suggestions for chip list
   List<Suggestion> suggestions = new ArrayList<Suggestion>();

   // creating a create calendar event suggested action
   CreateCalendarEventAction createCalendarEventAction = new CreateCalendarEventAction();
   calendarEventAction.setTitle("My calendar event");
   calendarEventAction.setDescription("Description of the calendar event");
   calendarEventAction.setStartTime("2020-06-30T19:00:00Z");
   calendarEventAction.setEndTime("2020-06-30T20:00:00Z");

   // creating a suggested action based on a create calendar event action
   SuggestedAction suggestedAction = new SuggestedAction();
   suggestedAction.setText("Save to calendar");
   suggestedAction.setPostbackData("postback_data_1234");
   suggestedAction.setCreateCalendarEventAction(createCalendarEventAction);

   // attaching action to a suggestion
   Suggestion suggestion = new Suggestion();
   suggestion.setAction(suggestedAction);

   suggestions.add(suggestion);

   // Send simple text message with the suggestion action
   rbmApiHelper.sendTextMessage(
      "Hello, world!",
      "+12223334444",
      suggestions
   );
} catch(Exception e) {
   e.printStackTrace();
}
این کد گزیده ای از یک عامل نمونه RBM است.

پایتون

# Reference to RBM Python client helper and messaging object structure
from rcs_business_messaging import rbm_service
from rcs_business_messaging import messages

# Create a calendar event suggested action
suggestions = [
      messages.CreateCalendarEventAction('Save to Calendar',
                             'reply:postback_data_1234',
                             '2020-06-30T19:00:00Z',
                             '2020-06-30T20:00:00Z',
                             'My calendar event',
                             'Description of the calendar event')

]

# Create text message to send to user
text_msg = messages.TextMessage('Hello, world!')
cluster = messages.MessageCluster().append_message(text_msg)

# Append suggestions for the message to send to the user
for suggestion in suggestions:
    cluster.append_suggestion_chip(suggestion)

# Send a simple message with suggested action to the device
cluster.send_to_msisdn('+12223334444')
این کد گزیده ای از یک عامل نمونه RBM است.

سی شارپ

using Google.Apis.RCSBusinessMessaging.v1.Data;
using RCSBusinessMessaging;
…

// Create an instance of the RBM API helper
RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation,
                                                 projectId);

// Create a calendar event action
CreateCalendarEventAction calendarEventAction = new CreateCalendarEventAction
{
    Title = "My calendar event",
    Description = "Description of the calendar event",
    StartTime = "2020-06-30T19:00:00Z",
    EndTime = "2020-06-30T20:00:00Z"
};

// Attach the calendar event action to a suggested action
SuggestedAction suggestedAction = new SuggestedAction
{
    CreateCalendarEventAction = calendarEventAction,
    Text = "Save to calendar",
    PostbackData = "postback_data_1234"
};

// Attach the action to a suggestion object
Suggestion suggestion = new Suggestion
{
    Action = suggestedAction
};

List<Suggestion> suggestions = new List<Suggestion>
{
    suggestion
};

rbmApiHelper.SendTextMessage(
    "Hello, world!",
    "+12223334444",
    suggestions
);
این کد گزیده ای از یک عامل نمونه RBM است.

لیست تراشه های پیشنهادی

نماینده شما لیست های تراشه های پیشنهادی را با پیام هایی برای هدایت اقدامات بعدی کاربران ارسال می کند. لیست تراشه فقط زمانی نمایش داده می شود که پیام مرتبط در پایین مکالمه باشد. هر پیام بعدی در مکالمه (از طرف کاربر یا نماینده شما) فهرست تراشه ها را بازنویسی می کند.

تراشه های موجود در لیست پاسخ های پیشنهادی و اقدامات پیشنهادی هستند.

لیست تراشه ها حداکثر شامل 11 تراشه پیشنهادی است و هر برچسب تراشه می تواند حداکثر 25 کاراکتر داشته باشد.

برای گزینه های قالب بندی و مقدار، AgentContentMessage را ببینید.

کارت های غنی

هنگامی که نیاز به ارسال تکه ای از اطلاعات، رسانه یا پیشنهادات مرتبط دارید، باید یک کارت غنی ارسال کنید. کارت های غنی به نماینده شما اجازه می دهند چندین واحد اطلاعات را در یک پیام ارسال کند.

کارت های غنی می توانند شامل موارد زیر باشند:

  • تصویر/فیلم
  • متن عنوان
  • متن توضیحات
  • فهرستی از پاسخ‌های پیشنهادی و اقدامات پیشنهادی (حداکثر 4)

یک کارت غنی می‌تواند شامل همه موارد فهرست شده باشد، اما یک کارت باید حداقل دارای یک تصویر، ویدیو یا عنوان باشد تا معتبر باشد. یک کارت غنی می‌تواند حداکثر شامل چهار اقدام پیشنهادی یا پاسخ پیشنهادی باشد. نمی‌تواند شامل ترکیبی از اقدامات پیشنهادی و پاسخ‌های پیشنهادی روی یک کارت باشد.

نماینده شما می تواند چندین کارت غنی را با هم در یک چرخ فلک کارت غنی ارسال کند.

ارتفاع کارت

کارت ها به صورت عمودی گسترش می یابند تا با محتویاتشان مطابقت داشته باشند. کارت های ریچ دارای حداقل ارتفاع 112 DP و حداکثر ارتفاع 344 DP هستند. اگر محتویات کارت به اندازه کافی بزرگ نباشد که حداقل ارتفاع کارت را پر کند، کارت گسترش می یابد و ارتفاع اضافی را با فضای خالی پر می کند.

رسانه موجود در کارت های غنی باید یکی از سه ارتفاع را داشته باشد:

  • کوتاه: 112 DP
  • متوسط: 168 DP
  • قد: 264 DP

اگر رسانه با ابعاد درون کارت با توجه به ارتفاع انتخاب شده مطابقت نداشته باشد، پیش نمایش رسانه با بزرگنمایی و برش رسانه انتخاب می شود.

مثال

کد زیر یک کارت غنی با یک تصویر و پاسخ های پیشنهادی ارسال می کند. برای گزینه‌های قالب‌بندی و مقدار، به RichCard مراجعه کنید.

حلقه

curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_ID&agentId=AGENT_ID" \
-H "Content-Type: application/json" \
-H "User-Agent: curl/rcs-business-messaging" \
-H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \
-d "{
  'contentMessage': {
    'richCard': {
      'standaloneCard': {
        'thumbnailImageAlignment': 'RIGHT',
        'cardOrientation': 'VERTICAL',
        'cardContent': {
          'title': 'Hello, world!',
          'description': 'RBM is awesome!',
          'media': {
            'height': 'TALL',
            'contentInfo':{
              'fileUrl': 'http://www.google.com/logos/doodles/2015/googles-new-logo-5078286822539264.3-hp2x.gif',
              'forceRefresh': 'false'
            }
          },
          'suggestions': [
            {
              'reply': {
                'text': 'Suggestion #1',
                'postbackData': 'suggestion_1'
              }
            },
            {
              'reply': {
                'text': 'Suggestion #2',
                'postbackData': 'suggestion_2'
              }
            }
          ]
        }
      }
    }
  }
}"

Node.js

// Reference to RBM API helper
const rbmApiHelper = require('@google/rcsbusinessmessaging');

// Suggested replies to be used in the card
let suggestions = [
   {
      reply: {
         'text': 'Suggestion #1',
         'postbackData': 'suggestion_1',
      },
   },
   {
      reply: {
         'text': 'Suggestion #2',
         'postbackData': 'suggestion_2',
      },
   },
];

// Image to be displayed by the card
let imageUrl = 'http://www.google.com/logos/doodles/2015/googles-new-logo-5078286822539264.3-hp2x.gif';

// Definition of the card parameters
let params = {
   messageText: 'Hello, world!',
   messageDescription: 'RBM is awesome!',
   msisdn: '+12223334444',
   suggestions: suggestions,
   imageUrl: imageUrl,
   height: 'TALL',
};

// Send rich card to device
rbmApiHelper.sendRichCard(params, function(response) {
   console.log(response);
});
این کد گزیده ای از یک عامل نمونه RBM است.

جاوا

import com.google.api.services.rcsbusinessmessaging.v1.model.StandaloneCard;
import com.google.api.services.rcsbusinessmessaging.v1.model.Suggestion;
import com.google.rbm.cards.CardOrientation;
import com.google.rbm.cards.MediaHeight;
import com.google.rbm.RbmApiHelper;
import com.google.rbm.SuggestionHelper;
…

try {
   // Create an instance of the RBM API helper
   RbmApiHelper rbmApiHelper = new RbmApiHelper();

   // Create suggestions for chip list
   List<Suggestion> suggestions = new ArrayList<Suggestion>();
   suggestions.add(
      new SuggestionHelper("Suggestion #1", "suggestion_1").getSuggestedReply());

   suggestions.add(
      new SuggestionHelper("Suggestion #2", "suggestion_2").getSuggestedReply());

   String imageUrl = "http://www.google.com/logos/doodles/2015/googles-new-logo-5078286822539264.3-hp2x.gif";

   // Create a standalone rich card to send to the user
   StandaloneCard standaloneCard = rbmApiHelper.createStandaloneCard(
       "Hello, world!",
       "RBM is awesome!",
       imageUrl,
       MediaHeight.MEDIUM,
       CardOrientation.VERTICAL,
       suggestions
   );

   rbmApiHelper.sendStandaloneCard(standaloneCard, "+12223334444");
} catch(Exception e) {
   e.printStackTrace();
}
این کد گزیده ای از یک عامل نمونه RBM است.

پایتون

# Reference to RBM Python client helper and messaging object structure
from rcs_business_messaging import rbm_service
from rcs_business_messaging import messages

# Suggested replies to be used in the card
suggestions = [
      messages.SuggestedReply('Suggestion #1', 'reply:suggestion_1'),
      messages.SuggestedReply('Suggestion #2', 'reply:suggestion_2')
]

# Image to be displayed by the card
image_url = 'http://www.google.com/logos/doodles/2015/googles-new-logo-5078286822539264.3-hp2x.gif';

# Define rich card structure
rich_card = messages.StandaloneCard('VERTICAL',
                                    'Hello, world!',
                                    'RBM is awesome!',
                                    suggestions,
                                    image_url,
                                    None,
                                    None,
                                    'MEDIUM')

# Append rich card and send to the user
cluster = messages.MessageCluster().append_message(rich_card)
cluster.send_to_msisdn('+12223334444')
این کد گزیده ای از یک عامل نمونه RBM است.

سی شارپ

using Google.Apis.RCSBusinessMessaging.v1.Data;
using RCSBusinessMessaging;
using RCSBusinessMessaging.Cards;
…

// Create an instance of the RBM API helper
RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation,
                                             projectId);

List<Suggestion> suggestions = new List<Suggestion>
{
   // Create suggestion chips
   new SuggestionHelper("Suggestion #1", "suggestion_1").SuggestedReply(),
   new SuggestionHelper("Suggestion #2", "suggestion_2").SuggestedReply()
};

string imageUrl = "http://www.google.com/logos/doodles/2015/googles-new-logo-5078286822539264.3-hp2x.gif";

// Create rich card with suggestions
StandaloneCard standaloneCard = rbmApiHelper.CreateStandaloneCard(
   "Hello, world!",
   "RBM is awesome",
   imageUrl,
   MediaHeight.TALL,
   CardOrientation.VERTICAL,
   suggestions
);

// Send rich card to user
rbmApiHelper.SendStandaloneCard(standaloneCard, "+12223334444");
این کد گزیده ای از یک عامل نمونه RBM است.

چرخ و فلک کارت غنی

هنگامی که نیاز به ارائه چندین گزینه برای کاربر دارید، از یک چرخ فلک کارت غنی استفاده کنید. چرخ فلک‌ها چندین کارت غنی را به هم متصل می‌کنند و به کاربران امکان می‌دهند آیتم‌ها را با هم مقایسه کنند و به هر کدام به صورت جداگانه واکنش نشان دهند.

چرخ فلک ها ممکن است حاوی حداقل دو و حداکثر ده کارت غنی باشند. کارت های غنی در چرخ و فلک باید با الزامات کلی کارت غنی برای محتوا و ارتفاع مطابقت داشته باشند.

مانند کارت‌های غنی ، بسیاری از عوامل (مانند وضوح صفحه، تراکم پیکسل و ترجیحات کاربر) بر نحوه ظاهر کارت‌ها برای کاربران نهایی تأثیر می‌گذارند. با این حال، در یک چرخ فلک، ارتفاع چند کارت اول ارتفاع همه کارت‌های چرخ و فلک را مشخص می‌کند و ارتفاع کارت بر عنوان، توضیحات و برش پیشنهاد تأثیر می‌گذارد.

اگر دستگاهی به دلیل محدودیت‌های نمایشگر یا ارتفاع کارت نتواند همه عناصر کارت را نمایش دهد، RBM کارت را تا زمانی که بتواند روی دستگاه نمایش داده شود، با استفاده از منطق زیر کوتاه می‌کند:

  1. توضیحات را به یک خط کاهش دهید.
  2. عنوان را به یک خط کاهش دهید.
  3. از انتهای لیست تعریف شده، پیشنهادهایی را که در کارت نمی گنجند حذف کنید.
  4. توضیحات را حذف کنید
  5. عنوان را حذف کنید

برای جلوگیری از کوتاه شدن، عناوین و توضیحات را تا حد امکان کوتاه نگه دارید. برای رسانه های بلند، از عنوان و توضیحات یا یک پیشنهاد استفاده کنید. برای رسانه های متوسط، حداکثر از دو پیشنهاد استفاده کنید. برای رسانه های کوتاه، حداکثر از سه پیشنهاد استفاده کنید. برای قرار دادن چهار پیشنهاد، رسانه را در کارت وارد نکنید.

کارت‌ها را از نظر اندازه و طول محتوا تقریباً برابر نگه دارید، و در صورت لزوم، کارت‌های بزرگ‌تر را در چرخ و فلک قرار دهید تا از کوتاه شدن کارت‌های بعدی جلوگیری شود.

مثال

کد زیر یک چرخ فلک کارت غنی را ارسال می کند. برای گزینه‌های قالب‌بندی و مقدار، به RichCard مراجعه کنید.

حلقه

curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_ID&agentId=AGENT_ID" \
-H "Content-Type: application/json" \
-H "User-Agent: curl/rcs-business-messaging" \
-H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \
-d "{
  'contentMessage': {
    'richCard': {
      'carouselCard': {
        'cardWidth':'MEDIUM',
        'cardContents': [
          {
            'title':'Card #1',
            'description':'The description for card #1',
            'suggestions': [
              {
                'reply': {
                  'text':'Card #1',
                  'postbackData':'card_1'
                }
              }
            ],
            'media': {
              'height':'MEDIUM',
              'contentInfo': {
                'fileUrl':'https://storage.googleapis.com/kitchen-sink-sample-images/cute-dog.jpg',
                'forceRefresh':'false'
              }
            }
          },
          {
            'title':'Card #2',
            'description':'The description for card #2',
            'suggestions': [
              {
                'reply': {
                  'text':'Card #2',
                  'postbackData':'card_2'
                }
              }
            ],
            'media': {
              'height':'MEDIUM',
              'contentInfo': {
                'fileUrl':'https://storage.googleapis.com/kitchen-sink-sample-images/elephant.jpg',
                'forceRefresh': 'false'
              }
            }
          }
        ]
      }
    }
  }
}"

Node.js

// Reference to RBM API helper
const rbmApiHelper = require('@google/rcsbusinessmessaging');

// Images for the carousel cards
let card1Image = 'https://storage.googleapis.com/kitchen-sink-sample-images/cute-dog.jpg';
let card2Image = 'https://storage.googleapis.com/kitchen-sink-sample-images/elephant.jpg';

// Define the card contents for a carousel with two cards, each with one suggested reply
let cardContents = [
   {
      title: 'Card #1',
      description: 'The description for card #1',
      suggestions: [
         {
            reply: {
               text: 'Card #1',
               postbackData: 'card_1',
            }
         }
      ],
      media: {
         height: 'MEDIUM',
         contentInfo: {
            fileUrl: card1Image,
            forceRefresh: false,
         },
      },
   },
   {
      title: 'Card #2',
      description: 'The description for card #2',
      suggestions: [
         {
            reply: {
               text: 'Card #2',
               postbackData: 'card_2',
            }
         }
      ],
      media: {
         height: 'MEDIUM',
         contentInfo: {
            fileUrl: card2Image,
            forceRefresh: false,
         },
      },
   },
];

// Definition of carousel card
let params = {
   msisdn: '+12223334444',
   cardContents: cardContents,
};

// Send the device the carousel card defined above
rbmApiHelper.sendCarouselCard(params, function(response) {
   console.log(response);
});
این کد گزیده ای از یک عامل نمونه RBM است.

جاوا

import com.google.api.services.rcsbusinessmessaging.v1.model.CardContent;
import com.google.api.services.rcsbusinessmessaging.v1.model.Suggestion;
import com.google.rbm.cards.CardOrientation;
import com.google.rbm.cards.CardWidth;
import com.google.rbm.cards.MediaHeight;
import com.google.rbm.RbmApiHelper;
import com.google.rbm.SuggestionHelper;
…

try {
            // Create an instance of the RBM API helper
            RbmApiHelper rbmApiHelper = new RbmApiHelper();

            List cardContents = new ArrayList();

            // Images for the carousel cards
            String card1Image = "https://storage.googleapis.com/kitchen-sink-sample-images/cute-dog.jpg";

            // Create suggestions for first carousel card
            List card1Suggestions = new ArrayList();
            card1Suggestions.add(
                new SuggestionHelper("Card #1", "card_1"));

            cardContents.add(
                new StandaloneCardHelper(
                    "Card #1",
                    "The description for card #1",
                    card1Image,
                    card1Suggestions)
                    .getCardContent(MediaHeight.SHORT)
            );

            // Images for the carousel cards
            String card2Image = "https://storage.googleapis.com/kitchen-sink-sample-images/elephant.jpg";

            // Create suggestions for second carousel card
            List card2Suggestions = new ArrayList();
            card2Suggestions.add(
                new SuggestionHelper("Card #2", "card_2"));

            cardContents.add(
                new StandaloneCardHelper(
                    "Card #2",
                    "The description for card #2",
                    card2Image,
                    card2Suggestions)
                    .getCardContent(MediaHeight.SHORT)
            );

            // Send the carousel to the user
            rbmApiHelper.sendCarouselCards(cardContents, CardWidth.MEDIUM, "+12223334444");
        } catch(Exception e) {
            e.printStackTrace();
        }
این کد گزیده ای از یک عامل نمونه RBM است.

پایتون

# Reference to RBM Python client helper and messaging object structure
from rcs_business_messaging import rbm_service
from rcs_business_messaging import messages

# Images for the carousel cards
card_image_1 = 'https://storage.googleapis.com/kitchen-sink-sample-images/cute-dog.jpg';
card_image_2 = 'https://storage.googleapis.com/kitchen-sink-sample-images/elephant.jpg';

# Suggested replies to be used in the cards
suggestions1 = [
      messages.SuggestedReply('Card #1', 'reply:card_1')
]

suggestions2 = [
      messages.SuggestedReply('Card #2', 'reply:card_2')
]

# Define the card contents for a carousel with two cards,
# each with one suggested reply
card_contents = []
card_contents.append(messages.CardContent('Card #1',
                                          'The description for card #1',
                                          card_image_1,
                                          'MEDIUM',
                                          suggestions1))

card_contents.append(messages.CardContent('Card #2',
                                          'The description for card #2',
                                          card_image_2,
                                          'MEDIUM',
                                          suggestions2))

# Send the device the carousel card defined above
carousel_card = messages.CarouselCard('MEDIUM', card_contents)
cluster = messages.MessageCluster().append_message(carousel_card)
cluster.send_to_msisdn('+12223334444')
این کد گزیده ای از یک عامل نمونه RBM است.

سی شارپ

using Google.Apis.RCSBusinessMessaging.v1.Data;
using RCSBusinessMessaging;
using RCSBusinessMessaging.Cards;
…

// Create an instance of the RBM API helper
RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation,
                                             projectId);

// Image references to be used in the carousel cards
string card1Image = "https://storage.googleapis.com/kitchen-sink-sample-images/cute-dog.jpg";
string card2Image = "https://storage.googleapis.com/kitchen-sink-sample-images/elephant.jpg";

// Suggestion chip lists to be used in carousel cards
List<Suggestion> suggestions1 = new List<Suggestion>
{
   new SuggestionHelper("Card #1", "card_1").SuggestedReply()
};

List<Suggestion> suggestions2 = new List<Suggestion>
{
   new SuggestionHelper("Card #2", "card_2").SuggestedReply()
};

// Create the card content for the carousel
List<CardContent> cardContents = new List<CardContent>
{
   // Add items as card content
   new StandaloneCardHelper(
                    "Card #1",
                    "The description for card #1",
                    card1Image,
                    suggestions1).GetCardContent(),
   new StandaloneCardHelper(
                    "Card #2",
                    "The description for card #2",
                    card2Image,
                    suggestions2).GetCardContent()
};

// Send the carousel to the user
rbmApiHelper.SendCarouselCards(cardContents, CardWidth.MEDIUM, msisdn);
این کد گزیده ای از یک عامل نمونه RBM است.