我如何使用 boto3 发送 api 请求并获得答案?

How can i send api requests and get the answers using boto3?

我已经在 Lex 上构建了我的机器人。

我正在尝试在 python 上与它交互,以发送请求(句子)并解析答案。

为此,我现在花了一些时间阅读和重读这些文档:https://boto3.readthedocs.io/en/latest/reference/services/lex-runtime.html#LexRuntimeService.Client.generate_presigned_url

但我似乎无法理解如何发送这些请求以及哪个函数实际上会给我机器人的答案。

你试过post_text()方法了吗?

import boto3 
client = boto3.client('lex-runtime')
response = client.post_text(
    botName='string',
    botAlias='string',
    userId='string',
    sessionAttributes={
        'string': 'string'
    },
    requestAttributes={
        'string': 'string'
    },
    inputText='string'
) 

此函数将为您提供来自机器人的答案,并将其存储在 response 变量中。
在 Lambda 函数中编写代码并授予访问 Lex 的权限。

希望对您有所帮助。