0.0.4 • Published 4 years ago

botium-connector-grpc v0.0.4

Weekly downloads
13
License
MIT
Repository
github
Last release
4 years ago

Botium Connector for GRPC Endpoint

NPM

Codeship Status for codeforequity-at/botium-connector-grpc npm version license

This is a Botium connector for testing your chatbot published on gRPC server.

Did you read the Botium in a Nutshell articles? Be warned, without prior knowledge of Botium you won't be able to properly use this library!

How it works

Botium calls your gRPC endpoint by transforming the Botium internal message representation to match in your .proto file defined schema.

It can be used as any other Botium connector with all Botium Stack components:

Requirements

  • Node.js and NPM
  • a bot published on a gRPC server
  • a project directory on your workstation to hold test cases, Botium configuration and a .proto file

Install Botium and gRPC Connector

When using Botium CLI:

> npm install -g botium-cli
> npm install -g botium-connector-grpc
> botium-cli init
> botium-cli run

When using Botium Bindings:

> npm install -g botium-bindings
> npm install -g botium-connector-grpc
> botium-bindings init mocha
> npm install && npm run mocha

When using Botium Box: Not integrated yet!

Connecting gRPC chatbot to Botium

First you need .proto file, which describe your server schema, then create a botium.json in your project directory with the corresponding gRPC configurations:

{
  "botium": {
    "Capabilities": {
      "PROJECTNAME": "Botium Project GRPC",
      "CONTAINERMODE": "grpc",
      "GRPC_URL": "localhost:50051",
      "GRPC_PROTO_PATH": "../echoserver/protos/botiumgrpc.proto",
      "GRPC_PROTO_PACKAGE": "botium",
      "GRPC_PROTO_SERVICE": "Echo",
      "GRPC_REQUEST_METHOD": "getReply",
      "GRPC_REQUEST_MESSAGE": "{\"text\": \"{{msg.messageText}}\", \"user_name\": \"botium\"}",
      "GRPC_RESPONSE_FIELD": "text"
    }
  }
}

To check the configuration (Botium CLI required), run the hello command to say "hello" to check connectivity or run the emulator to bring up a chat interface in your terminal window:

> botium-cli hello

or

> botium-cli emulator

Botium setup is ready, you can begin to write your test cases with BotiumScript.

How to start sample

There is a simple Echo-bot included, see samples/echoserver folder. You have to start it before running the samples:

> npm install && npm start

Now you can start the included Botium samples:

> cd ./samples/echo
> npm install && npm test

Supported Capabilities

Set the capability CONTAINERMODE to grpc to activate this connector.

GRPC_URL

gRPC server URL

GRPC_PROTO_PATH

Relative url of you .proto file

GRPC_PROTO

The content of .proto file in plain text. (If you use this capability, you have to remove GRPC_PROTO_PATH capability.)

GRPC_PROTO_PACKAGE

The package defined in your .proto file

GRPC_PROTO_SERVICE

The service defined in your .proto file

GRPC_REQUEST_METHOD

The method defined in your .proto file for the service

GRPC_REQUEST_MESSAGE_TEMPLATE

Mustache template for conversating the Botium internal message structure to the gRPC request object as required according to the .proto file.

The Mustache view contains the Botium internal message structure in the msg field, see Botium Wiki. Example:

...
"GRPC_REQUEST_MESSAGE_TEMPLATE": {
   "user_name": "botium",
   "text": "{{msg.messageText}}"
},
...

GRPC_RESPONSE_TEXTS_JSONPATH

JSONPath expression to extract the message text from the gRPC response.

GRPC_RESPONSE_BUTTONS_JSONPATH (NOT IMPLEMENTED YET!!!)

JSONPath expression to extract button texts from the gRPC response.

GRPC_RESPONSE_MEDIA_JSONPATH (NOT IMPLEMENTED YET!!!)

JSONPath expression to extract media attachments from the gRPC response.