मैसेज की रसीदें भेजें और पाएं

मैसेज की रसीद भेजने वाले को सूचना देती है कि उसके मैसेज मिल गए हैं या उसे पढ़ लिया गया है. रसीदों की मदद से, उपयोगकर्ता देख सकते हैं कि एजेंट ने उनके मैसेज पढ़ लिए हैं, ताकि उन्हें जवाब का पता हो. आपका एजेंट भी यह तय कर सकता है कि उपयोगकर्ताओं को मैसेज कब मिलेंगे और वे उन्हें कब पढ़ेंगे. इससे, आप बेहतर इंटरैक्शन डिज़ाइन के लिए रसीद मेट्रिक ट्रैक कर सकते हैं.

एजेंट को उनके वेबहुक पर रसीदें भेजी जाती हैं. जिस तरह आपको मैसेज पाने के विकल्प मिलते हैं, उसी तरह रसीद पाएं और उसे प्रोसेस करें.

अगर कोई उपयोगकर्ता एक ही बार में कई मैसेज पाने या पढ़ने के ज़रिए एक बार में कई रसीदें भेजता है, तो एक पेलोड में सभी मैसेज की रसीदें शामिल होती हैं. हर मैसेज में दी गई सूचना देखें कि वह किस मैसेज से जुड़ा है.

रसीद के टाइप

Business Messages की मदद से, डिलीवरी की रसीद दी जाती है और मैसेज पढ़े जाते हैं.

उपयोगकर्ताओं से मिली रसीदें

एजेंट, लोगों से ये रसीदें पा सकते हैं:

  • डिलीवरी की रसीदों (DELIVERED) से पता चलता है कि उपयोगकर्ता को एजेंट से मैसेज मिला है.
  • मैसेज पढ़े जाने की सूचना (READ) से पता चलता है कि उपयोगकर्ता ने एजेंट का मैसेज पढ़ा है.

उपयोगकर्ता, मैसेज पढ़े जाने की सूचना भेजने से ऑप्ट आउट कर सकते हैं. ऑप्ट आउट करने के बावजूद उपयोगकर्ता एजेंट से रसीदें पा सकते हैं.

एजेंट से मिली रसीदें

उपयोगकर्ता, एजेंट से मैसेज पढ़े जाने की सूचना पा सकते हैं.

मैसेज पढ़े जाने की सूचना (READ) से पता चलता है कि एजेंट ने उपयोगकर्ता का मैसेज पढ़ लिया है. अगर बातचीत को एक से ज़्यादा लाइव एजेंट मैनेज कर रहे हैं, तो ईमेल पढ़े जाने की सूचना का मतलब है कि कम से कम एक एजेंट ने उपयोगकर्ता का मैसेज पढ़ लिया है.

फ़ॉर्मैट

उपयोगकर्ताओं से मिली रसीदें

उपयोगकर्ताओं से डिलीवरी की रसीदों का फ़ॉर्मैट नीचे दिया गया है:

{
  "agent": "brands/BRAND_ID/agents/AGENT_ID",
  "conversationId": "CONVERSATION_ID",
  "customAgentId": "CUSTOM_AGENT_ID",
  "sendTime": "SEND_TIME",
  "receipts" : {
    "receipts": [
      {
        "message": "conversations/CONVERSATION_ID/messages/MESSAGE_ID",
        "receiptType": "DELIVERED",
      }
    ],
    "createTime": "RECEIPTS_CREATION_TIME",
  },
}

उपयोगकर्ताओं से मिली रसीदों का फ़ॉर्मैट इस तरह का होता है:

{
  "agent": "brands/BRAND_ID/agents/AGENT_ID",
  "conversationId": "CONVERSATION_ID",
  "customAgentId": "CUSTOM_AGENT_ID",
  "sendTime": "SEND_TIME",
  "receipts" : {
    "receipts": [
      {
        "message": "conversations/CONVERSATION_ID/messages/MESSAGE_ID",
        "receiptType": "READ",
      }
    ],
    "createTime": "RECEIPTS_CREATION_TIME",
  },
}

फ़ॉर्मैटिंग और वैल्यू के विकल्पों के लिए, UserMessage और Receipts देखें.

एजेंट से मिली रसीदें

यह कोड, एजेंट से पढ़े जाने की सूचना भेजता है:

यूआरएल

curl -X PATCH \
-H "`./oauth2l header --json 'PATH_TO_SERVICE_ACCOUNT_KEY' businessmessages`" \
-H "Content-Type: application/json" \
-d '{
  "receiptType": "READ"
}' \
"https://businessmessages.googleapis.com/v1/conversations/CONVERSATION_ID/messages/MESSAGE_ID/receipt"

Node.js

const businessmessages = require('businessmessages');
const uuidv4 = require('uuid/v4');
const {google} = require('googleapis');

// Initialize the Business Messages API
let bmApi = new businessmessages.businessmessages_v1.Businessmessages({});

// Set the scope that we need for the Business Messages API
const scopes = [
  'https://www.googleapis.com/auth/businessmessages',
];

// Set the private key to the service account file
const privatekey = require('PATH_TO_SERVICE_ACCOUNT_KEY');

/**
 * Initializes the Google credentials for calling the
 * Business Messages API.
 */
async function initCredentials() {
  // Configure a JWT auth client
  let authClient = new google.auth.JWT(
      privatekey.client_email,
      null,
      privatekey.private_key,
      scopes,
  );

  return new Promise(function(resolve, reject) {
    // Authenticate request
    authClient.authorize(function(err, tokens) {
      if (err) {
        reject(false);
      } else {
        resolve(authClient);
      }
    });
  });
}

/**
 * Sends a read receipt to a specific messageId.
 *
 * @param {string} conversationId The unique id for this user and agent.
 * @param {string} messageId The unique id for this message.
 */
async function sendReadReceipt(conversationId, messageId) {
  let authClient = await initCredentials();

  // Create the payload for sending a read receipt
  let apiParams = {
    auth: authClient,
    name: 'conversations/' + conversationId + '/messages/' + messageId + '/receipt',
    resource: {
      receiptType:'READ'
    }
  };

  // Call the updateReceipt create function using the
  // Business Messages client library
  bmApi.conversations.messages.updateReceipt(apiParams,
    {auth: authClient}, (err, response) => {
    console.log(err);
    console.log(response);
  });
}

sendReadReceipt('CONVERSATION_ID', 'MESSAGE_ID');
यह कोड, Node.js Business Messages की क्लाइंट लाइब्रेरी के मुताबिक है.

Java

import com.google.api.client.googleapis.services.AbstractGoogleClientRequest;
import com.google.api.client.http.HttpBackOffUnsuccessfulResponseHandler;
import com.google.api.client.http.HttpRequest;
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.client.util.ExponentialBackOff;
import com.google.api.services.businessmessages.v1.Businessmessages;
import com.google.api.services.businessmessages.v1.model.BusinessMessagesReceipt;

import com.google.api.services.businessmessages.v1.model.*;
import java.io.FileInputStream;
import java.util.Arrays;
import java.util.UUID;

public class ReadReceiptSample {
  /**
   * Initializes credentials used by the Business Messages API.
   */
  private static Businessmessages.Builder getBusinessMessagesBuilder() {
    Businessmessages.Builder builder = null;
    try {
      GoogleCredential credential = GoogleCredential
            .fromStream(new FileInputStream("PATH_TO_SERVICE_ACCOUNT_KEY"));

      credential = credential.createScoped(Arrays.asList(
            "https://www.googleapis.com/auth/businessmessages"));

      credential.refreshToken();

      HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
      JacksonFactory jsonFactory = JacksonFactory.getDefaultInstance();

      // Create instance of the Business Messages API
      builder = new Businessmessages
        .Builder(httpTransport, jsonFactory, null)
        .setApplicationName("Sample Application");

      // Set the API credentials and endpoint
      builder.setHttpRequestInitializer(credential);
    } catch (Exception e) {
      e.printStackTrace();
    }

    return builder;
  }

  public static void main(String args[]) {
    try{
      String conversationId = "CONVERSATION_ID";
      String messageId = "MESSAGE_ID";

      // Create client library reference
      Businessmessages.Builder builder = getBusinessMessagesBuilder();

     // Create a new read receipt
     Businessmessages.Conversations.Messages.UpdateReceipt request
       = builder.build().conversations().messages()
         .updateReceipt("conversations/" + conversationId + "/messages/" + messageId + "/receipt",
           new BusinessMessagesReceipt().setReceiptType("READ"));

      // Set up retries with exponential backoff
      HttpRequest httpRequest =
          ((AbstractGoogleClientRequest) request).buildHttpRequest();

      httpRequest.setUnsuccessfulResponseHandler(new
          HttpBackOffUnsuccessfulResponseHandler(
          new ExponentialBackOff()));

      // Execute request
      httpRequest.execute();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}
यह कोड Java Business Messages क्लाइंट लाइब्रेरी के मुताबिक है.

Python

from oauth2client.service_account import ServiceAccountCredentials
from businessmessages import businessmessages_v1_client as bm_client
from businessmessages.businessmessages_v1_messages import (
    BusinessMessagesReceipt)

credentials = ServiceAccountCredentials.from_json_keyfile_name(
    'PATH_TO_SERVICE_ACCOUNT_KEY',
    scopes=['https://www.googleapis.com/auth/businessmessages'])

client = bm_client.BusinessmessagesV1(credentials=credentials)

conversation_id = 'CONVERSATION_ID'
message_id = 'MESSAGE_ID'

read_receipt = BusinessMessagesReceipt(
    name=f"conversations/{conversation_id}/messages/{message_id}/receipt",
    receiptType=BusinessMessagesReceipt.ReceiptTypeValueValuesEnum.READ
)

# Send the message
bm_client.BusinessmessagesV1.ConversationsMessagesService(
    client=client).UpdateReceipt(request=read_receipt)
यह कोड Python Business Messages क्लाइंट लाइब्रेरी के मुताबिक है.

फ़ॉर्मैटिंग और वैल्यू के विकल्पों के लिए, ReceiptType देखें.