ユーザーを認証する

一般的に、エージェントは、ユーザーが会話中に提供する情報以外に、コミュニケーションしているユーザーに関する分析情報をほとんど保持しません。ただし、エージェントは OAuth でユーザーを認証することで、ユーザー ID の確認、会話のカスタマイズ、ユーザーに代わってアクションを実行できます。

この会話フローでは、ユーザーがアカウントにクレジットを追加することを選択します。エージェントは、ユーザーに本人確認のためのログイン、既知のユーザー情報の取得、クレジットの注文を行うよう促します。

  1. ユーザーがエージェントとの会話を開始します。
  2. ユーザーがレスポンスの入力を開始すると、エージェントに入力イベントが送信されます。

    {
      "agent": "brands/1111/agents/2222",
      "conversationId": "3333",
      "customAgentId": "oauth",
      "requestId": "1234567890",
      "userStatus": {
        "isTyping": "true",
        "createTime": "2020-10-02T15:01:23.045123456Z",
      },
      "sendTime": "2020-10-02T15:01:24.045123456Z",
    }
    
  3. ユーザーが、アカウントに 5 つのクレジットを追加することをご希望の場合、メッセージを送信します。

    {
      "agent": "brands/1111/agents/2222",
      "conversationId": "3333",
      "customAgentId": "oauth",
      "requestId": "123123123",
      "message": {
        "messageId": "4444",
        "name": "conversations/12345/messages/67890",
        "text": "Hi, I'd like to add 5 credits to my account",
        "createTime": "2020-10-02T15:05:23.045123456Z",
      },
      "context": {
        "entryPoint": "PLACESHEET",
        "userInfo": {
          "displayName": "Michael",
          "userDeviceLocale": "en",
        },
        "resolvedLocale": "en",
      }
      "sendTime": "2020-10-02T15:05:24.045123456Z",
    }
    
  4. エージェントが、サポートを受けることができます。ご自身のアカウントにログインして、認証リクエストの提案に沿って続行してください。

    clientIdscopes は、OAuth プロバイダによって定義されます。エージェントは、OAuth プロバイダの要件に従って codeChallenge 値を生成します。

    curl -X POST "https://businessmessages.googleapis.com/v1/conversations/3333/messages" \
    -H "Content-Type: application/json" \
    -H "`oauth2l header --json path/to/service/account/key.json businessmessages`" \
    -d "{
      'messageId': '5555',
      'text': 'I can help you with that. Sign into your account to continue.',
      'suggestions': [
        {
          'AuthenticationRequest': {
            'clientId': 'oauth_client_id_1234567890',
            'codeChallenge': 'code_challenge',
            'scopes': [
              'account',
              'billing',
            ],
          },
        },
      ],
      'representative': {
        'avatarImage': 'https://oauth.agent/bot-avatar.jpg',
        'displayName': 'OAuth Agent',
        'representativeType': 'BOT'
      }
    }"
    
  5. ユーザーがメッセージを受信し、認証リクエストの提案をタップして、アカウントにログインします。

  6. エージェントは、OAuth 認証コードを含むメッセージを authenticationResponse.code フィールドに受信します。

    {
      "agent": "brands/1111/agents/2222",
      "conversationId": "3333",
      "customAgentId": "oauth",
      "requestId": "1234567895",
      "authenticationResponse": {
        "code": "fkhoe541658sfk684d135j186mngkjdrt5425415a2s1dfa68s4edf",
        },
      }
      "sendTime": "2020-10-02T15:01:24.045123456Z",
    }
    
  7. エージェントは OAuth プロバイダと通信し、認証コードをアクセス トークンと交換して、ユーザーのアカウント情報を取得します。

  8. エージェントが「ログインしてくれてありがとう」と伝える。現在、クレジットは 2 つです。確認のため、お客様のアカウントに 5 つのクレジットを追加し、デフォルトのお支払い方法である「はい」と「いいえ」の返信メッセージとして請求します。

    curl -X POST "https://businessmessages.googleapis.com/v1/conversations/3333/messages" \
    -H "Content-Type: application/json" \
    -H "`oauth2l header --json path/to/service/account/key.json businessmessages`" \
    -d "{
      'messageId': '7777',
      'text': 'Thanks for signing in. You currently have 2 credits. To confirm, you'd like to me to add 5 credits to your account and bill your default payment method?',
      'suggestions': [
        {
          'reply': {
            'text': 'Yes',
            'postbackData': 'process-transaction',
          },
        },
        {
          'reply': {
            'text': 'No',
            'postbackData': 'cancel-transaction',
          },
        },
      ],
      'representative': {
        'avatarImage': 'https://oauth.agent/bot-avatar.jpg',
        'displayName': 'OAuth Agent',
        'representativeType': 'BOT'
      }
    }"
    
  9. ユーザーが [はい] をタップして返信の候補をタップします。

    {
      "agent": "brands/1111/agents/2222",
      "conversationId": "3333",
      "customAgentId": "oauth",
      "requestId": "1234567898",
      "suggestionResponse": {
        "message": "conversations/333/messages/8888",
        "postbackData": "process-transaction",
        "createTime": "2020-10-02T15:01:26.045123456Z",
        "text": "Yes",
        "suggestionType": "REPLY",
      }
      "sendTime": "2020-10-02T15:01:27.045123456Z",
    }
    
  10. エージェントは、OAuth アクセス トークンを使用してトランザクションを処理し、「Great」というメッセージを送信します。お客様のアカウントに 5 つのクレジットを追加しました。他に何かご不明な点はございませんか?

    curl -X POST "https://businessmessages.googleapis.com/v1/conversations/3333/messages" \
    -H "Content-Type: application/json" \
    -H "`oauth2l header --json path/to/service/account/key.json businessmessages`" \
    -d "{
      'messageId': '9999',
      'text': 'Great. I just added 5 credits to your account. Is there anything else I can help you with?',
      'representative': {
        'avatarImage': 'https://oauth.agent/bot-avatar.jpg',
        'displayName': 'OAuth Agent',
        'representativeType': 'BOT'
      }
    }"
    
  11. ユーザーが「いいえ」と送信した。

    {
      "agent": "brands/1111/agents/2222",
      "conversationId": "3333",
      "customAgentId": "oauth",
      "requestId": "123123133",
      "message": {
        "messageId": "4444",
        "name": "conversations/12345/messages/101010",
        "text": "No, thanks",
        "createTime": "2020-10-02T15:05:23.045123456Z",
      },
      "context": {
        "entryPoint": "PLACESHEET",
        "userInfo": {
          "displayName": "Michael",
          "userDeviceLocale": "en",
        },
        "resolvedLocale": "en",
      }
      "sendTime": "2020-10-02T15:05:28.045123456Z",
    }
    
  12. エージェントが「お問い合わせいただきありがとうございます。今後ともよろしくお願いいたします。」

    curl -X POST "https://businessmessages.googleapis.com/v1/conversations/3333/messages" \
    -H "Content-Type: application/json" \
    -H "`oauth2l header --json path/to/service/account/key.json businessmessages`" \
    -d "{
      'messageId': '11111111',
      'text': 'Thanks for contacting us. Have a great day!',
      'representative': {
        'avatarImage': 'https://oauth.agent/bot-avatar.jpg',
        'displayName': 'OAuth Agent',
        'representativeType': 'BOT'
      }
    }"