Freigeben über


InvokeResponseFactory class

Provides methods for formatting various invoke responses a bot can send to respond to an invoke request.

Remarks

All of these functions return an InvokeResponse object, which can be passed as input to generate a new invokeResponse activity.

This example sends an invoke response that contains an adaptive card.


const myCard = {
   type: "AdaptiveCard",
   body: [
    {
      "type": "TextBlock",
      "text": "This is a sample card"
    }],
    $schema: "http://adaptivecards.io/schemas/adaptive-card.json",
    version: "1.4"
 };

const invokeResponse = InvokeResponseFactory.adaptiveCard(myCard);
await context.sendActivity({
   type: ActivityTypes.InvokeResponse,
   value: invokeResponse,
 });

Methods

adaptiveCard(unknown)

Create an invoke response from an adaptive card.

The type of the invoke response is application/vnd.microsoft.card.adaptive indicates the request was successfully processed, and the response includes an adaptive card that the client should display in place of the current one.

createInvokeResponse(StatusCodes, unknown)

Create an invoke response with status code and response value.

errorResponse(InvokeResponseErrorCode, string)

Create an invoke response with error code and message.

The type of the invoke response is application/vnd.microsoft.error indicates the request was failed to processed.

textMessage(string)

Create an invoke response from a text message. The type of the invoke response is application/vnd.microsoft.activity.message indicates the request was successfully processed.

Method Details

adaptiveCard(unknown)

Create an invoke response from an adaptive card.

The type of the invoke response is application/vnd.microsoft.card.adaptive indicates the request was successfully processed, and the response includes an adaptive card that the client should display in place of the current one.

static function adaptiveCard(card: unknown): InvokeResponse<any>

Parameters

card

unknown

The adaptive card JSON payload.

Returns

InvokeResponse<any>

An InvokeResponse object.

createInvokeResponse(StatusCodes, unknown)

Create an invoke response with status code and response value.

static function createInvokeResponse(statusCode: StatusCodes, body?: unknown): InvokeResponse<any>

Parameters

statusCode

StatusCodes

The status code.

body

unknown

The value of the response body.

Returns

InvokeResponse<any>

An InvokeResponse object.

errorResponse(InvokeResponseErrorCode, string)

Create an invoke response with error code and message.

The type of the invoke response is application/vnd.microsoft.error indicates the request was failed to processed.

static function errorResponse(errorCode: InvokeResponseErrorCode, errorMessage: string): InvokeResponse<any>

Parameters

errorCode
InvokeResponseErrorCode

The status code indicates error, available values:

  • 400 (BadRequest): indicate the incoming request was invalid.
  • 500 (InternalServerError): indicate an unexpected error occurred.
errorMessage

string

The error message.

Returns

InvokeResponse<any>

An InvokeResponse object.

textMessage(string)

Create an invoke response from a text message. The type of the invoke response is application/vnd.microsoft.activity.message indicates the request was successfully processed.

static function textMessage(message: string): InvokeResponse<any>

Parameters

message

string

A text message included in a invoke response.

Returns

InvokeResponse<any>

An InvokeResponse object.