getMessageByIndex method

Future<Message> getMessageByIndex(
  1. int messageIndex
)

Implementation

Future<Message> getMessageByIndex(int messageIndex) async {
  if (!hasMessages) {
    throw NotFoundException(
      code: 'NotFoundException',
      message: 'Conversation does not have any messages.',
    );
  }

  try {
    final result = await TwilioConversations()
        .conversationApi
        .getMessageByIndex(sid, messageIndex);

    if (result.sid == null) {
      throw NotFoundException(
        code: 'NotFoundException',
        message: 'No message found with index: $messageIndex',
      );
    }

    final message = Message.fromPigeon(result);
    return message;
  } on PlatformException catch (err) {
    throw TwilioConversations.convertException(err);
  }
}