データデータ アクションしたGoogle Cloud Functionの例
次のコンテンツには、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を構成する.
/ **
*すべてのHTTPリクエストに応答します。
*
* @param {!express:Request} reqHTTPリクエストコンテキスト。
* @param {!express:Response} resHTTP応答コンテキスト。
* /
exports.testAction =(req、res)=> {
if(req.body.inputNumber1 <= 0 || req.body.inputNumber2 <= 0){
res.status(400).send({エラー: '入力はゼロより大きくなければなりません'});
} そうしないと {
応答= createResponse(req);
res.status(200).send(response);
}
};
/ **
*すべてのHTTPリクエストに応答します。
*
* @param {!express:Request} reqHTTPリクエストコンテキスト。
* /
関数createResponse(req){
var response = {};
response.sumOfNumber1AndNumber2 = req.body.inputNumber1 + req.body.inputNumber2;
応答を返します。
}
データ アクション
次のJSONは、サンプルの関数を実行するデータデータ アクションです。 あなたはにインポートするJSONの圧縮バージョンをダウンロードすることができデータ アクション : テスト・クラウド・ファンクション・データ・アクション (.zip)。 詳細については、以下を参照してください。 統合のためのカスタムアクションの作成 および 統合のためのデータアクションをインポートまたはエクスポートする.
requestUrlTemplate はトリガーURLで、機能の場所 (us-central1)、プロジェクト名 (businesscallingapi)、機能名 (function-test-action)を含み、https://{location-of-function}-{project-owning-function}/{function-name} 形式である。 詳細については、 統合のカスタムアクションに構成を追加する.
{{
"名前": "Test-Cloud-Function-Math-Example-Exported 2020-07-28 @ 11:06"、
"integrationType": 「google-cloud-data-actions」、
"actionType": "習慣"、
「設定」: {{
"リクエスト": {{
"requestUrlTemplate": "https://us-central1-businesscallingapi.cloudfunctions.net/function-test-action-math-example"。
"requestType "を指定します。 "役職"、
「ヘッダー」: {}
},
"応答"。 {{
"translationMap": {}、
"translationMapDefaults": {}、
"successTemplate": 「$ {rawResult}」
}
}、
"契約する": {{
"入力": {{
"inputSchema": {{
"題名": 「合計入力」、
"タイプ": "物体"、
"プロパティ": {{
"inputNumber1": {{
"タイプ": "番号"
}、
"inputNumber2": {{
"タイプ": "番号"
}
}、
"additionalProperties": true
}
}、
"出力": {{
"successSchema": {{
"題名": 「合計応答」、
"タイプ": "物体"、
"プロパティ": {{
"sumOfNumber1AndNumber2": {{
"タイプ": "番号"
}
}、
"additionalProperties": true
}
}
}、
"安全": true
}
テストデータ アクションことを確認するためにデータ アクションエラーなしで実行されます。 詳細については、 統合のためのテストデータアクション。
詳しくは、Google data actions integration について をご覧ください。