メモ:   この記事は、Google Cloud Functionsで使用した場合のGoogleデータアクション統合に適用されます。

次のコンテンツには、Google Cloud関数の例と、関数を実行するデータデータ アクションが含まれています。 Google Cloud Platformプロジェクトに関数を追加し、データアクションをGenesys Cloud組織にインポートして、Googleデータアクション統合で使用できます。

詳細については、 Google Cloud Functionsのセットアップ

Google Cloud関数の例

次のコードは、JavaScriptで記述されたGoogle Cloud Functionです。 このコードをコピーして、Google Cloud Platformプロジェクトに関数を作成します。 Google Cloud Platform で関数を処理するように設定し、関数の戻り値のレスポンスがapplication/json for Content-Type であることを確認してください。 詳細については、 Google Cloud Platformを構成する.

/**
* Responds to any HTTP request.
*
* @param {!express:Request} req HTTP request context.
* @param {!express:Response} res HTTP response context.
*/
exports.testAction = (req, res) => {
    if (req.body.inputNumber1 <=0 || req.body.inputNumber2 <= 0) {
        res.status(400).send( { error: 'Inputs must be greater than zero' } );
    } else {
        let response = createResponse(req);
        res.status(200).send(response);
    }
};
 
/**
* Responds to any HTTP request.
*
* @param {!express:Request} req HTTP request context.
*/
function createResponse(req) {
   
    var response = {};
    response.sumOfNumber1AndNumber2 = req.body.inputNumber1 + req.body.inputNumber2;
    return response;
}

データ アクション

次のJSONは、サンプルの関数を実行するデータデータ アクションです。 あなたはにインポートするJSONの圧縮バージョンをダウンロードすることができデータ アクション : テスト・クラウド・ファンクション・データ・アクション (.zip)。 詳細については、以下を参照してください。 統合のためのカスタムアクションの作成 および 統合のためのデータアクションをインポートまたはエクスポートする.

requestUrlTemplate はトリガーURLで、機能の場所 (us-central1)、プロジェクト名 (businesscallingapi)、機能名 (function-test-action)を含み、https://{location-of-function}-{project-owning-function}/{function-name} 形式である。 詳細については、 統合のカスタムアクションに構成を追加する.

{
  "name": "Test-Cloud-Function-Math-Example - Exported 2020-07-28 @ 11:06",
  "integrationType": "google-cloud-data-actions",
  "actionType": "custom",
  "config": {
    "request": {
      "requestUrlTemplate": "https://us-central1-businesscallingapi.cloudfunctions.net/function-test-action-math-example",
      "requestType": "POST",
      "headers": {}
    },
    "response": {
      "translationMap": {},
      "translationMapDefaults": {},
      "successTemplate": "${rawResult}"
    }
  },
  "contract": {
    "input": {
      "inputSchema": {
        "title": "sum-input",
        "type": "object",
        "properties": {
          "inputNumber1": {
            "type": "number"
          },
          "inputNumber2": {
            "type": "number"
          }
        },
        "additionalProperties": false
      }
    },
    "output": {
      "successSchema": {
        "title": "sum-response",
        "type": "object",
        "properties": {
          "sumOfNumber1AndNumber2": {
            "type": "number"
          }
        },
        "additionalProperties": false
      }
    }
  },
  "secure": false
}

テストデータ アクションことを確認するためにデータ アクションエラーなしで実行されます。 詳細については、 統合のためのテストデータアクション

詳しくは、Google data actions integration について をご覧ください。