startConversation method

Future<StartConversationResponse> startConversation({
  1. required String botAliasId,
  2. required String botId,
  3. required String localeId,
  4. required StartConversationRequestEventStream requestEventStream,
  5. required String sessionId,
  6. ConversationMode? conversationMode,
})

Starts an HTTP/2 bidirectional event stream that enables you to send audio, text, or DTMF input in real time. After your application starts a conversation, users send input to Amazon Lex V2 as a stream of events. Amazon Lex V2 processes the incoming events and responds with streaming text or audio events.

Audio input must be in the following format: audio/lpcm sample-rate=8000 sample-size-bits=16 channel-count=1; is-big-endian=false.

If the optional post-fulfillment response is specified, the messages are returned as follows. For more information, see PostFulfillmentStatusSpecification.

  • Success message - Returned if the Lambda function completes successfully and the intent state is fulfilled or ready fulfillment if the message is present.
  • Failed message - The failed message is returned if the Lambda function throws an exception or if the Lambda function returns a failed intent state without a message.
  • Timeout message - If you don't configure a timeout message and a timeout, and the Lambda function doesn't return within 30 seconds, the timeout message is returned. If you configure a timeout, the timeout message is returned when the period times out.
For more information, see Completion message.

If the optional update message is configured, it is played at the specified frequency while the Lambda function is running and the update message state is active. If the fulfillment update message is not active, the Lambda function runs with a 30 second timeout.

For more information, see Update message

The StartConversation operation is supported only in the following SDKs:

May throw AccessDeniedException. May throw InternalServerException. May throw ThrottlingException. May throw ValidationException.

Parameter botAliasId : The alias identifier in use for the bot that processes the request.

Parameter botId : The identifier of the bot to process the request.

Parameter localeId : The locale where the session is in use.

Parameter requestEventStream : Represents the stream of events to Amazon Lex V2 from your application. The events are encoded as HTTP/2 data frames.

Parameter sessionId : The identifier of the user session that is having the conversation.

Parameter conversationMode : The conversation type that you are using the Amazon Lex V2. If the conversation mode is AUDIO you can send both audio and DTMF information. If the mode is TEXT you can only send text.

Implementation

Future<StartConversationResponse> startConversation({
  required String botAliasId,
  required String botId,
  required String localeId,
  required StartConversationRequestEventStream requestEventStream,
  required String sessionId,
  ConversationMode? conversationMode,
}) async {
  final headers = <String, String>{
    if (conversationMode != null)
      'x-amz-lex-conversation-mode': conversationMode.value,
  };
  final response = await _protocol.sendRaw(
    payload: requestEventStream,
    method: 'POST',
    requestUri:
        '/bots/${Uri.encodeComponent(botId)}/botAliases/${Uri.encodeComponent(botAliasId)}/botLocales/${Uri.encodeComponent(localeId)}/sessions/${Uri.encodeComponent(sessionId)}/conversation',
    headers: headers,
    exceptionFnMap: _exceptionFns,
  );
  final $json = await _s.jsonFromResponse(response);
  return StartConversationResponse(
    responseEventStream: StartConversationResponseEventStream.fromJson($json),
  );
}