步驟 4:建立機器人 (AWS CLI) - Amazon Lex V1

如果您使用的是 Amazon Lex V2,請參閱 Amazon Lex V2 指南

 

如果您使用的是 Amazon Lex V1,我們建議您將機器人升級到 Amazon Lex V2。我們不再向 V1 添加新功能,強烈建議所有新機器人使用 V2。

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

步驟 4:建立機器人 (AWS CLI)

OrderFlowersBot 機器人有一個意圖,即您在之前的步驟所建立的 OrderFlowers 意圖。若要執行本練習中的命令,您必須知道要執行命令的區域。如需區域的列表,請參閱 模型建置配額

注意

以下 AWS CLI 範例格式適用於 Unix、Linux 和 macOS。用於 Windows 時,請將 "\$LATEST" 變更為 $LATEST

建立 OrderFlowersBot 機器人 (AWS CLI)
  1. 建立名為 OrderFlowersBot.json 的文字檔案。從 OrderFlowersBot.json 複製 JSON 程式碼到文字檔案。

  2. 在 AWS CLI 中呼叫 PutBot 操作來建立機器人。此範例格式適用於 Unix、Linux 和 macOS。用於 Windows 時,請以插入號 (^) 取代每一行結尾處的 Unix 接續字元斜線 (\)。

    aws lex-models put-bot \ --region region \ --name OrderFlowersBot \ --cli-input-json file://OrderFlowersBot.json

    伺服器會隨之回應。當建立或更新機器人時,status 欄位會設定為 BUILDING。這表示機器人尚未準備就緒。若要判斷機器人何時準備就緒,請使用下一步中的 GetBot 操作。

    {
        "status": "BUILDING", 
        "intents": [
            {
                "intentVersion": "$LATEST", 
                "intentName": "OrderFlowers"
            }
        ], 
        "name": "OrderFlowersBot", 
        "locale": "en-US", 
        "checksum": "checksum", 
        "abortStatement": {
            "messages": [
                {
                    "content": "Sorry, I'm not able to assist at this time", 
                    "contentType": "PlainText"
                }
            ]
        }, 
        "version": "$LATEST", 
        "lastUpdatedDate": timestamp, 
        "createdDate": timestamp, 
        "clarificationPrompt": {
            "maxAttempts": 2, 
            "messages": [
                {
                    "content": "I didn't understand you, what would you like to do?", 
                    "contentType": "PlainText"
                }
            ]
        }, 
        "voiceId": "Salli", 
        "childDirected": false, 
        "idleSessionTTLInSeconds": 600, 
        "processBehavior": "BUILD",
        "description": "Bot to order flowers on the behalf of a user"
    }
    

  3. 若要判斷您的新機器人是否已準備就緒,請執行下列命令。重複此命令,直到 status 欄位傳回 READY 為止。此範例格式適用於 Unix、Linux 和 macOS。用於 Windows 時,請以插入號 (^) 取代每一行結尾處的 Unix 接續字元斜線 (\)。

    aws lex-models get-bot \ --region region \ --name OrderFlowersBot \ --version-or-alias "\$LATEST"

    在回應中尋找 status 欄位:

    {
        "status": "READY", 
        
        ...
        
    }
    

後續步驟

步驟 5:測試機器人 (AWS CLI)