addOutgoingMessage()

in src/components/Chat/ChatSession.js [201:234]


  addOutgoingMessage(data) {
    const message = modelUtils.createOutgoingTranscriptItem(
      PARTICIPANT_MESSAGE,
    { data: data.text, type: ContentType.MESSAGE_CONTENT_TYPE.TEXT_PLAIN },
      this.thisParticipant
    );
    console.log("addOutgoingMessage, messageItem is:", message);

    this._addItemsToTranscript([message]);

    this.isOutgoingMessageInFlight = true;

    this.client
      .sendMessage(message.content)
      .then((response) => {
        console.log("send success");
        console.log(response);
        this._replaceItemInTranscript(
          message,
          modelUtils.createTranscriptItemFromSuccessResponse(
            message,
            response
          )
        );

        this.isOutgoingMessageInFlight = false;
        return response;
      })
      .catch((error) => {
        this.isOutgoingMessageInFlight = false;

        this._failMessage(message);
      });
  }