This is the multi-page printable view of this section.
Click here to print.
Return to the regular view of this page.
Aura Mocks Server
Aura Mocks server
Description of Aura Mocks Server, a tool to provide a mock for any of the services that use Aura Bot or that are used by Aura Bot, and guidelines for working with it
Introduction
Aura Mocks Server is a server that provides a mock for any of the services that use aura-bot or that are used by aura-bot.
This component defines rest services that allow aura-bot system to run without the need for any other external system to provide these services.
Aura Mocks Server is composed by different plugins, which provide functionality to the tool and can work independently.
The current documentation includes:
This project is in development phase, so the necessary services will be completed over time.
1 - Installation
Aura Mocks server installation
Guidelines for the installation, testing and deployment of Aura Mocks Server
Introduction
These instructions will allow you to get a copy of the project running on your local machine for development and testing purposes.
The following pre-requirements are needed:
- nodeJS installed version: 12 or higher
$ node --version
Installation
Run tests
This project uses tslint to validate the coding style.
Code style tests
These tests perform the validation coding rules defined in aura using the tslint tool.
You can validate the code using:
$ npm run lint
Deployment
This project uses Jenkins to generate the docker image in the azure registry.
You can download the image using pull:
docker pull auraregistry.azurecr.io/aura/aura-mocks-server:<VERSION>
Build local docker image
To build docker image execute:
$ docker build -f ./delivery/docker/Dockerfile -t auraregistry.azurecr.io/aura-mocks-server .
Run server
To start mock server:
$ docker run -d -p 3000:3000 auraregistry.azurecr.io/aura-mocks-server
This starts a server listening on port 3000
Deploy
To deploy in performance environments, there is a convinient deployment yaml in aurak8s repository at tools/mocks/deployment.yml so you just need to run kubectl apply -f tools/mocks/deployment.yml.
Developer notes
The folder structure used for development is:
src
├── api // Statics API code
├── modules // Modules code (jsonserver)
├── scripts // Scripts
└── shared // Shared code between APIs and modules.
├── common
└── services
Versioning
We use [SemVer] (http://semver.org/) for versioning.
For all available versions, look at the tags in this repository.
2 - Plugins
Aura mocks server plugins
aura-mocks-server plugins are components that provide different functionalities to this component
Introduction
aura-mocks-server is composed of plugins, which provide functionality to the tool. Plugins work independently, the same way as a service in a microservices oriented architecture: isolated, self-contained and without affecting other existing functionality in the system.
Discover in the current documents detailed information regarding aura-mocks-server plugins:
Global plugins catalog
The available global plugins of aura-mocks-server are included in the Github global plugins repository.
Aura Platform Team is progressively documenting each plugin within the current documents. Check the already documented ones in the left sidebar index.
Types of plugins
There are different types of plugins:
-
Api. REST services that perform specific tasks not associated with the communication with a channel.
-
Client. These plugins define clients that can be used to communicate with a channel. These clients are normally used by processor plugins.
-
Processor. Plugins in charge of communicating with a channel, transforming the message received from a source channel to a destination channel.
-
Service. Utility plugins to be used by the rest of plugins.
Plugins management
As indicated in the previous section, aura-mocks-server uses the library@architect/architect for the management of plugins, so it is the architect library that is responsible for managing the dependencies injection in each module.
To create the architect application, aura-mocks-server uses the PluginManager module (located in the modules/plugin-manager folder). This module starts as the rest of modules at the aura-mocks-server start-up.
The PluginManager performs the following tasks:
- It starts the architect application with the plugins defined in
plugin-config.json file, located at the root of the aura-mocks-server component.
- It adds the core modules to the IOC context. See the section modules added by aura-mocks-server.
- It stores the information of each module defined in the plugins.
An example to define aura-mocks-server-example-service plugin of the previous section is shown below:
/* file: plugin-config.json */
[
"./lib/plugins/aura-mocks-server-example-service",
]
Currently, the plugins are in the src/plugins folder of aura-mocks-server, but in the future these plugins should be independent libraries and could be charged by library name (for example: @telefonica/aura-mocks-server-example-service).
Apart from the aura-mocks-server core environment variables, each plugin can define its own specific variables.
Plugin basic structure
Currently, aura-mocks-server uses @architect/architect library for plugins management.
A basic plugin must define at least:
- A
package.json file defining the library, like any other JavaScript library, with a plugin section defining which modules it consumes and supplies.
- A source code file that defines the modules that it supplies (
index.ts for example).
The structure of this basic plugin is as follows:
aura-mocks-server-example-service
├── index.ts
└── package.json
A couple of examples with the content of each file are included below:
/* file: index.ts */
import { PluginType, registerPlugin } from '@telefonica/xxxx-server-common';
import { v4 as uuidv4 } from 'uuid';
import { Services } from './example-consume-services';
export = registerPlugin([
{
type: PluginType.Service, // Plugin service type
name: 'exampleService', // Name of the plugin service
instance: { // [provides] Instance that provides the module
getUniqueId() {
return uuidv4();
}
},
services: Services // [consumes] Needed modules are added here
}
]);
/* file: package.json */
{
"name": "@telefonica/aura-mocks-server-example-service",
"version": "1.0.0",
"main": "index.js",
"private": true,
"plugin": {
"consumes": [
"configurationManager"
],
"provides": [
"exampleService"
]
}
}
The modules specified in the plugin.consumes field define the services that are needed by this plugin. The modules specified in the plugin.provides field define the modules that this plugin offers.
Plugins modules
aura-mocks-server currently adds three modules that can be used by the different plugins. To use them, it is only necessary to add the package.json dependencies on plugin.consumes (like any other module/component).
- configurationManager: Module with the aura-mocks-server configuration information.
- auramocks-serverCache: Module to manage the aura-mocks-server cache.
- prometheus: Service for metrics management.
A plugin can provide one or more plugin modules and each plugin module can be of a different type. Each type of module is intended to add a specific functionality to aura-mocks-server.
The existing types are defined in PluginType, which are described in the following sections.
export enum PluginType {
Api = 'Api',
Client = 'Client',
Processor = 'Processor',
Service = 'Service'
}
2.1 - administration-api plugin
aura-mocks-administration-api plugin
Plugin that returns Aura Mocks Server data.
Description
The aura-mocks-administration-api plugin returns data info from Aura Mocks Server, such as app, cache or plugins.
Find more information in the Github repository:
https://github.com/Telefonica/aura-mocks-server/tree/master/src/plugins/aura-mocks-administration-api
This is part of aura-mocks-server project.
Administration Endpoints API
| Enpoint |
Method |
Group |
description |
| /administration/heapStatistics |
GET |
App |
Get heap statistics |
| /administration/heapSnapshot |
GET |
App |
Get heap snapshot |
| /administration/cache |
GET |
Cache |
Get cache |
| /administration/cache/stats |
GET |
Cache |
Get cache stats |
| /administration/plugins |
GET |
Plugins |
Get plugins |
GET: /administration/heapStatistics
Return Aura Mocks Server data info.
{
"aura-mocks-server-1.0.0": {...}
}
GET: /administration/heapSnapshot
Generate and upload snapshot to Azure Storage.
GET: /administration/cache
Return cache data info.
{
"info": {
"Server": {...},
"Clients": {...},
"Memory": {...},
"Persistence": {...},
"Stats": {...},
"Replication": {...},
"CPU": {...},
"Modules": {...},
"Errorstats": {...},
"Cluster": {...},
"Keyspace": {...}
}
}
GET: /administration/cache/stats
Return cache stats data.
GET: /administration/plugins
Return plugins data info.
[
{
"name": "redisStorageService",
"pkg": "@telefonica/aura-redis-service",
"version": "1.0.0",
"package": "aura-mocks-redis-service",
"consumes": [
"configurationManager"
],
"provides": [
"redisStorageService"
]
}
]
2.2 - async-callback-api plugin
aura-mocks-async-callback-api plugin
Plugin that mocks asynchronous notification message
Description
The aura-mocks-async-callback-api plugin simulates aura-bridge asynchronous notification message for asynchronous API requests, both internal, such as file-manager or external, such as technical-problems-api in Kernel. It also adds several useful endpoints for the QA team and performance testing.
Find more information in the Github repository:
https://github.com/Telefonica/aura-mocks-server/tree/master/src/plugins/aura-mocks-async-callback-api
This is part of aura-mocks-server project.
Endpoints API
| Enpoint |
Method |
Group |
description |
| /async-callback/notifications |
GET |
Async Callback |
Get notifications |
| /async-callback/notifications |
DELETE |
Async Callback |
Delete notifications |
| /async-callback/notifications |
POST |
Async Callback |
Send notification |
GET: /async-callback/notifications
Get message by messageCorrelator. The query param messageCorrelator is mandatory.
DELETE: /async-callback/notifications
Delete message by messageCorrelator. The query param messageCorrelator is mandatory.
POST: /async-callback/notifications
Add new asynchronous notification message
{
"payload": {...},
"creation_date": "2019-08-08T15:19:48.259Z",
"user_id": "9a47b037-825f-4ae7-bf55-6290efd5d036"
}
2.3 - auraline-api plugin
aura-mocks-auraline-api plugin
Plugin that mocks Auraline.
Description
The aura-mocks-auraline-api plugin simulates aura-bridge for aura-bot Auraline callbacks and adds several useful endpoints for the QA Team and performance testing.
Find more information in the Github repository:
https://github.com/Telefonica/aura-mocks-server/tree/master/src/plugins/aura-mocks-auraline-api
This is part of aura-mocks-server project.
Endpoints API
| Enpoint |
Method |
Group |
description |
| /auraline/v1/activities |
GET |
Auraline |
Get activities |
| /auraline/v1/activities |
DELETE |
Auraline |
Delete activities |
| /auraline/v1/conversations/:conversationId/activities/:activityId |
POST |
Auraline |
Add activities |
| /auraline/v1/conversations/:conversationId/activities |
DELETE |
Auraline |
Delete activities |
GET: /auraline/v1/activities
Return activities by conversationId.
Query params:
| Name |
Type |
Description |
Mandatory |
| conversationId |
string |
Conversation id |
True |
| retries |
integer |
Number of retries |
False |
| timeBetweenRetries |
integer |
ms between retries |
False |
DELETE: /auraline/v1/activities
Delete activities by conversationId.
Query params:
| Name |
Type |
Description |
Mandatory |
| conversationId |
string |
Conversation id |
True |
POST: /auraline/v1/conversations/:conversationId/activities/:activityId
Push new Auraline activity for conversationId
DELETE: /auraline/v1/conversations/:conversationId/activities
Delete Auraline activities by conversationId
2.4 - bot-api plugin
aura-mocks-bot-api plugin
Plugin that mocks aura-bot
Description
The aura-mocks-bot-api plugin simulates Directline requests for aura-groot with several useful endpoints for the QA team and performance testing.
Find more information in the Github repository:
https://github.com/Telefonica/aura-mocks-server/tree/master/src/plugins/aura-mocks-bot-api
This is part of aura-mocks-server project.
Endpoints API
| Enpoint |
Method |
Group |
description |
| /api/messages |
POST |
bot |
Send messages: send messages. Optional param reply=true to send response with Directline format to aura-bridge |
| /api/messages |
GET |
bot |
Get messages |
| /api/messages |
DELETE |
bot |
Delete messages |
GET: /api/messages
Get message by to. The query param to is mandatory.
DELETE: /api/messages
Delete message by to. The query param to is mandatory.
POST: /api/messages
Add new aura-bot message.
{
"type": "message",
"id": "IiKY7bzb1Pd5VdtN4FZKmB-a|0000000",
"timestamp": "2021-01-28T16:02:49.6587305Z",
"serviceUrl": "https://directline.botframework.com/",
"channelId": "directline",
"from": {
"id": "ca9961f9-c6f0-3acd-5c72-ce2719f43ec9"
},
"conversation": {
"id": "IiKY7bzb1Pd5VdtN4FZKmB-a"
},
"textFormat": "plain",
"locale": "es-ES",
"channelData": {
"auraCommand": {
"type": "suggestion",
"value": {
"intent": "intent.common.greetings"
}
}
}
2.5 - data-store-api plugin
aura-mocks-data-store-api plugin
Plugin that mocks data-store
Description
The aura-mocks-data-store-api plugin simulates an API to manage documents in a generic way with several useful endpoints for the QA team and performance testing.
Find more information in the Github repository:
https://github.com/Telefonica/aura-mocks-server/tree/master/src/plugins/aura-mocks-data-store-api
This is part of aura-mocks-server project.
Endpoints API
Defines an API to manage documents in a generic way.
| Enpoint |
Method |
Group |
description |
| /data-store/sorted/:collection |
POST |
Data Store |
Save document |
| /data-store/sorted/:collection |
GET |
Data Store |
Find documents |
| /data-store/sorted/:collection/:id |
GET |
Data Store |
Get document in collection by id |
GET: /data-store/sorted/:collection
Get message by timestamp. The query param timestamp is mandatory.
DELETE: /data-store/sorted/:collection
Delete message by timestamp. The query param timestamp is mandatory.
POST: /data-store/sorted/:collection
Add new collection document.
2.6 - dynamic-settings-service plugin
aura-mocks-dynamic-settings-service plugin
Description of the aura-mocks-dynamic-settings-service plugin
Description
The aura-mocks-dynamic-settings-service plugin is responsible for loading profile configurations from an Azure account or locally to be used afterwards.
An attempt is made to collect data from the specified Azure Storage account and container. If nothing is found, a default file is collected locally from path src/plugins/aura-mocks-dynamic-settings-service/dynamic-settings-default.json. The active cron performs this check periodically.
Find more information in the Github repository:
https://github.com/Telefonica/aura-mocks-server/tree/master/src/plugins/aura-mocks-dynamic-settings-service
This is part of aura-mocks-server project.
Variables
| name |
type |
description |
mandatory |
| AURA_MOCKS_DYNAMIC_SETTINGS_SERVICE_CRON |
string |
Cron expression for dynamic settings loading |
no |
| AURA_MOCKS_DYNAMIC_SETTINGS_SERVICE_RESOURCE_CONTAINER |
string |
Container where dynamic settings file is stored |
no |
| AURA_MOCKS_DYNAMIC_SETTINGS_SERVICE_RESOURCE_PATH |
string |
Path to JSON configuration file used by dynamic settings service |
no |
Example of dynamic settings file
{
"type": "Local",
"plugins": [
{
"name": "auraMocksGenesysApi",
"settings": {
"pushProviders": [
{
"name": "default",
"pushUrl": "https://svc-ap-current.auracognitive.com/aura-services/v1/genesys/messages?apikey=123456",
"headers": {
"genesys-callback": "http://perf-mock.aura-mocks.svc"
}
}
],
"profiles": [
{
"name": "default",
"configuration": {
"chat": {
"updateAliasForEachRequest": true,
"autoMessages": [
{
"from": {
"nickname": "system",
"type": "External"
},
"type": "ParticipantJoined",
"timeout": 1
}
]
}
}
}
]
}
}
]
}
2.7 - genesys-api plugin
aura-mocks-genesys-api plugin
Plugin that mocks the behavior of Genesys, the call-center service used by Telefónica OBs.
Description
The aura-mocks-genesys-api plugin contains the services used by aura-bot and aura-bridge to work without real Genesys services.
These services are mainly:
Find more information in the Github repository:
https://github.com/Telefonica/aura-mocks-server/tree/master/src/plugins/aura-mocks-genesys-api
This is part of aura-mocks-server project.
Genesys API
Chat API Version 2
Genesys documentation: https://docs.genesys.com/Documentation/GMS/latest/API/ChatAPIv2
Currently, the mock for Genesys has the following endpoints implemented:
| Enpoint |
Method |
Group |
description |
| /genesys/2/chat/{serviceName} |
POST |
Chat |
Request Chat |
| /genesys/2/chat/{serviceName}/{chatId}/send |
POST |
Chat |
Send Message |
| /genesys/2/chat/{serviceName}/{chatId}/disconnect |
POST |
Chat |
Disconnect |
| /genesys/2/chat/{serviceName}/{chatId}/pushUrl |
POST |
Chat |
PushUrl |
Start a new chat
Steps
- Perform a
POST request to /Genesys/2/Chat/{ServiceName}
- When a new chat is created using the
POST request to “/Genesys/2/Chat/{ServiceName}”, the system uses the settings indicated in the profile parameter or uses the default profile configuration if this parameter is not informed (see Profiles mock API
- Send messages to chat using the endpoint
/genesys/2/chat/{serviceName}/{chatId}/send
You can change at any time the value of Pushurl using the endpoint /genesys/2/chat/{serviceName}/{chatId}/pushUrl
Sessions Mock API
To help in testing tasks, the mocks exposes a series of services associated with the sessions it manages and the profiles that can be used to start a conversation.
Sessions are identified by the chatId, so once a chat is created, you can check the session using /genesys/2/mock/sessions/{chatId}.
Endpoins
| Enpoint |
Method |
Group |
description |
| /genesys/2/mock/sessions |
GET |
Session |
Get chat mock sessions |
| /genesys/2/mock/sessions/{chatId} |
GET |
Session |
Get session by chatId |
| /genesys/2/mock/sessions/stats |
GET |
Session |
Get session stats |
| /genesys/2/mock/sessions/keys |
GET |
Session |
Get session keys |
| /genesys/2/mock/sessions |
DELETE |
Session |
Remove session |
Profiles Mock API
The profiles allow you to configure a different execution environment to the default environment, in order to receive answers in another address (Pushurl) and execute automatic actions when starting a new chat.
What are the profiles for?
When a new chat is created using the POST request /genesys/2/chat/{serviceName}, a profile is used to configure mainly two parameters:
pushUrl: It indicates the address where PUSH notifications will be sent.
autoMessages: Messages that will be executed automatically at the beginning of the conversation and using the waiting time indicated for each message.
See default profile settings
An example of configuration for the “default” profile is shown below:
// Post result to "/genesys/2/mock/profiles"
[
{
"profile": "default",
"settings": {
"chat": {
"pushUrl": "https://svc-ap-current.auracognitive.com/aura-services/v1/genesys/messages",
"autoMessages": [
{
"from": {
"nickname": "system",
"type": "External"
},
"type": "ParticipantJoined",
"timeout": 1
},
{
"from": {
"type": "External"
},
"type": "Message",
"timeout": 1,
"text": "You have approximately 15 minutes to be attended"
},
{
"from": {
"type": "External"
},
"type": "Message",
"timeout": 1,
"text": "Soon one of our agents will attend you personally"
},
{
"from": {
"nickname": "agent1",
"type": "Agent"
},
"type": "ParticipantJoined",
"timeout": 1
},
{
"from": {
"type": "Agent"
},
"type": "Message",
"timeout": 1,
"text": "Hello, I am an Agent, how can I help you?"
}
]
}
}
}
]
In the default configuration, once a new chat is created, the following messages will be executed:
- A second after starting the chat, the “system” (external) user will join conversation.
- After that, “system” will send a message “You have approximately 15 minutes to be attended” (1 second after the previous message).
- “system” will send a message “Soon one of our agents will attend you personally” (1 second after).
- “agent1” (Agent) user will join conversation (1 second after).
- “agent1” will send a message “Hello, I am an Agent, how can I help you?” (1 second after).
Endpoints
| Enpoint |
Method |
Group |
description |
| /genesys/2/mock/profiles |
GET |
Profile |
Get profiles |
| /genesys/2/mock/profiles/{profile} |
GET |
Profile |
Get profile by name |
| /genesys/2/mock/profiles/default |
POST |
Profile |
Set profile by name |
| /genesys/2/mock/profiles/reset |
GET |
Profile |
Reset profiles |
| /genesys/2/mock/chat/{serviceName}/{chatId}/send |
POST |
MockChat |
Send message directly to the session, with optional timeout |
Chat Mock API
You can send any type of event in chat using the service /genesys/2/mock/chat/{serviceName}/{chatId}/send. The format is similar to “autoMessages” for a profile.
The postman linked to this documentation contains an example of all types of events that can be sent to chat.
Postman
2.8 - json-server-api plugin
aura-mocks-json-server-api plugin
Module that mocks the behavior of any of the REST APIs called by aura-bot
Description
aura-mocks-json-server-api is a tool using express that allows you to generate REST services with predefined responses from a Javascript file that can be easily modified.
Find more information in the Github repository:
https://github.com/Telefonica/aura-mocks-server/tree/master/src/plugins/aura-mocks-json-server-api
This is part of aura-mocks-server project.
Create a simple “hello” response
You must create a file to store the information of your new response mocks in data/db/module (for our example, greetings.js):
data
├── db
│ ├── module
│ │ ├── greetings.js
Add to greetings.js the response to the request GET /greetings/hello:
module.exports = {
"configuration": {
"name": "greetings",
"basePath": "/greetings"
},
"routes": {
"/hello": {
"GET": {
"examples": {
"default": {
"status": 200,
"body": {
"response": "Hello from mock"
}
}
}
}
}
}
};
Now, you can make a call to:
<URL_MOCK_SERVER>/greetings/hello
That should answer with a:
{
"response": "Hello from mock"
}
Creating a more complex answer
For example, to create a POST service /aura-services/v1/users/:id, where the user is dynamic:
"routes": {
"/aura-services/v1/users/:id": {
"GET": {
"configuration": {
"getExampleKey": (req, res) => { return req.params && req.params.id ? req.params.id : 'default'; }
},
"examples": {
"default": {
"status": 200,
"body": {
"auraIdGlobal": "929285cb270001356476db33a4e31ce86402948213097e81717b50e549054cf2",
"auraId": "fb7926db-0283-41ef-a02f-541946090c92",
"userId": "85826044177A204DDEBCCEA98CE9439C3C770E03",
"channelId": "60f0ffda-e58a-4a96-aad9-d42be70b7b42",
"authorizationId": "",
"phoneNumber": "",
"idTokenHint": null
}
},
"fb7926db-0283-41ef-a02f-541946090c92": {
"status": 200,
"body": {
"auraIdGlobal": "929285cb270001356476db33a4e31ce86402948213097e81717b50e549054cf2",
"auraId": "fb7926db-0283-41ef-a02f-541946090c92",
"userId": "85826044177A204DDEBCCEA98CE9439C3C770E03",
"channelId": "60f0ffda-e58a-4a96-aad9-d42be70b7b42",
"authorizationId": "",
"phoneNumber": "",
"idTokenHint": null
}
}
}
}
}
}
How to get requests and responses automatically
The main idea is to obtain and generate all the requests in an automated way from the data sent and received by the aura-bot platform itself. In this way, there is no need to generate by hand each of the services required by the bot.
To obtain these requests, it is possible to use a sniffer and filter by the domains used by the aura-bot platform itself or use the aura-bot platform to record in a file all the requests and responses made (chosen option).
To use aura-bot platform as a request/response generator, you can temporarily modify the code as follows:
http-monkey-patcher.ts
line 1
import * as fs from 'fs';
before line 90
const requestResponse = {};
after line 122
parsedOptions.port = args[0].port;
after line 200: request.once ‘finish’
(requestResponse as any).request = {
type: 'request',
domain: host,
port: parsedOptions.port,
method: parsedOptions.method,
path: parsedOptions.path,
corr: this.getCorrelatorFromRequest(request) || CorrelatorUtil.noCorrelator,
headers: request.getHeaders(),
body: requestBody
};
after line 250: response.once ’end
(requestResponse as any).response = {
type: 'response',
domain: host,
method: parsedOptions.method,
status: response.statusCode,
path: parsedOptions.path,
body: responseBody,
drt: duration,
corr
};
fs.appendFile('/tmp/request-response-data.txt', `${JSON.stringify(requestResponse)}\n\n`, () => { });
To import the data obtained, check the documentation for json-server-import script
aura-mocks-json-server-api plugin scripts
Import requests/response to aura-mocks-server database
script: json-server-import.js
To import the information obtained previously, the script src/scripts/json-server-import.ts is used.
This script allows you to load the request / response information into the mock server database.
npm run jsonserver:import --file=/tmp/hello-greeting.txt
The previous sentence will load the requests, overwriting existing ones.
You can also debug the script code:
npm run jsonserver:import:debug --file=/tmp/hello-greeting.txt
How it works
The script will load in the JSON server database information of each request associated with the example named default. (All loaded requests are loaded as “samples” by default).
Examples are each of the responses that a request can return. You can create examples with a different identifier to default using the getExampleKey function (in configuration object) for that request:
...
"routes": {
"/aura-services/v1/users/:id": {
"GET": {
"configuration": {
"getExampleKey": (req, res) => { return req.params && req.params.id ? req.params.id : 'default'; }
},
...
In the previous configuration, the json-server-import script will get the example identifier using the id parameter obtained from the request URL itself. Thus, the request /aura-services/v1/users/e7c26f93-bf15-419b-8893-2728afad3b6c will create the example:
...
"examples": {
"e7c26f93-bf15-419b-8893-2728afad3b6c": {
"status": 200,
"body": {
"auraIdGlobal": "5c7ba5d26fa2945b3b9b29b64d6822edd914dd0d82cf28eae5287dd2a28b7768",
"auraId": "e7c26f93-bf15-419b-8893-2728afad3b6c",
"userId": "17c1ee02-0140-11ea-a69e-362b8e000000",
"channelId": "45494a5b-835a-4fff-a813-b3d2be529dbe",
"authorizationId": "",
"phoneNumber": "phone_number",
"idTokenHint": null
}
}
}
...
Show routes in aura-mocks-server database
script: json-server-routes.js
This script will show the routes stored in the JSON server database and the examples that each route contains.
npm run jsonserver:routes
aura-mocks-json-server-api plugin database
/v3/domain_classifier/default_query
Currently, the mocks service for apigw url /auracognitive/v3/domain_classifier/default_query is ready to respond to the following POST queries:
| Intent |
Channel |
Phrase (spanish) |
| intent.common.goodbyes |
mp |
hasta pronto |
| intent.common.greetings |
mp |
hola |
| intent.common.help |
mp |
ayuda |
| intent.common.swearwords |
mp |
joder |
| intent.common.thankyous |
mp |
gracias |
| intent.tv.content_get_info |
mp |
peliculas de fox |
| intent.tv.display |
mp |
quiero ver cuatro |
| intent.tv.none |
mp |
aabb |
| intent.tv.question_time_loc |
mp |
hora del partido del barcelona |
| intent.tv.search |
mp |
busca masterchef |
| intent.tv.search |
mp |
busca telediario |
| intent.tv.search_similar |
mp |
similar a telediario |
/aura-services/v1/users/:id
| User (auraId) |
Channel Name |
channelId |
| fb7926db-0283-41ef-a02f-541946090c92 |
mp |
60f0ffda-e58a-4a96-aad9-d42be70b7b42 |
2.9 - openai-api plugin
aura-mocks-openai-api plugin
Description of the aura-mocks-openai-api plugin that mocks some of the services defined in the Azure OpenAI Service, used mainly by the Aura Gateway API service.
Description
The aura-mocks-openai-api plugin contains the services used by aura-gateway-api to work without real OpenAI services.
Find more information in the Github repository:
https://github.com/Telefonica/aura-mocks-server/tree/master/src/plugins/aura-mocks-openai-api
Currently, the plugin mocks the following services:
This is part of aura-mocks-server project.
aura-mocks-openai-api API
Endpoints description
Currently, the mock for OpenAI has the following endpoints implemented:
| Enpoint |
Method |
Group |
description |
| /openai/deployments/:deployment_id/chat/completions |
POST |
Chat |
Create chat completions |
Create chat completions
The endpoint /openai/deployments/:deployment_id/chat/completions is used to create a new chat completion. It is a POST request that receives the following query parameters:
| Parameter |
Type |
Description |
| api-version |
string |
version of the API to be used |
The response can be modified using the content field of the request body.
Using a specific response
The content field of the request body can be used to return a specific response:
{
"messages": [
{
"role": "user",
"content": "error_400_content_filter"
}
]
}
Using retries profile
The content field of the request body can be used to return responses based on a profile. The retries profile allows to return different responses for each retry. Example:
{
"messages": [
{
"role": "user",
"content": "user2|retries:status-500&status-200"
}
]
}
In the example above, the retries profile will return the first response with status 500 and then the second response with status 200.
Defined responses
The following table shows the different mock responses that can be used:
| Mock response |
Description |
| error_400_content_filter |
Returns a 400 error with content filter error |
| error_401_incorrect_api_key |
Returns a 401 error with incorrect APIKey |
| error_429_exceeded_quota |
Returns a 429 error with exceeded quota |
| error_429_rate_limit_reached |
Returns a 429 error with rate limit reached |
| error_500_server_error |
Returns a 500 error with server error |
| error_503_engine_overloaded |
Returns a 503 error with engine overloaded |
| missing_response |
Returns a 200 response with an empty response body |
| success_length |
Returns a 200 success response |
| success_stop |
Returns a 200 success response with finish_reason stop |
The “error_429_exceeded_quota” and “error_429_rate_limit_reached” responses will have the “Retry-After” header set to 5 seconds.
2.10 - plugin-manager-service plugin
aura-mocks-plugin-manager-service plugin
Description of the aura-mocks-plugin-manager-service plugin
Description
The aura-mocks-plugin-manager-service plugin is responsible for registering the different plugins of project.
Find more information in the Github repository:
https://github.com/Telefonica/aura-mocks-server/tree/master/src/plugins/aura-mocks-plugin-manager-service
This is part of aura-mocks-server project.
2.11 - profiles-response-service plugin
aura-mocks-profiles-response-service plugin
Description and guidelines for working with the aura-mocks-profiles-response-service plugin
Introduction
The aura-mocks-profiles-response-service plugin provides the rest of the plugins a specific utility to employ profiles and perform different behaviors, depending on the information received in requests and the configuration by type.
Find more information in the Github repository:
https://github.com/Telefonica/aura-mocks-server/tree/master/src/plugins/aura-mocks-profiles-response-service
How to use
To use it, you must:
- Import services with injected plugins.
- Use Dynamic settings plugin to fetch the profile.
- Use
profileService to fetch the profile settings.
import { services } from './services';
const profiles: ProfileSettings[] = services.dynamicSettings?.getSettingsForPlugin('nameOfProfile')?.profiles;
const profileSettings: ProfileSettings = services.profileService.getProfile(profile, profiles);
Methods
getData
/**
* Get data of profile.
*
* @param {string} value Message identifier
* @returns {ProfileData} Profile data
*/
public getData(value: string): ProfileData {
Example
const profileData: ProfileData = services.profileService?.getData(profile);
isProfile
/**
* Determine whether the service contains a correct profile.
*
* @param {string} value Value to test
* @param {ProfileSettings[]} profiles Profile list
* @returns {boolean} Is profile?
*/
public isProfile(value: string, profiles: ProfileSettings[]): boolean {
getProfile
/**
* Get profile from value.
*
* @param {string} value Value to test
* @param {ProfileSettings[]} profiles Profile list
* @returns {ProfileSettings|undefined} Profile settings
*/
public getProfile(value: string, profiles: ProfileSettings[]): ProfileSettings | undefined {
Example
services.profileService.getProfile(profile, profiles);
executeProfile
/**
* Executes given profile.
*
* @param {ProfileSettings} profile Settings of channel.
* @param {object[]} savedMessages Messages stored in cache.
* @param {object} message Message sent by the bridge.
* @param {ResponseMessage} response Default response.
* @param {ProfileData} profileData Profile data
* @returns {ResponseResult} Response result.
*/
public executeProfile(
profile: ProfileSettings,
savedMessages: any[],
message: any,
response: ResponseMessage,
profileData: ProfileData
): ResponseResult {
Example
services.profileService.executeProfile(profileSettings, messages, message, {} as any, profileData);
executeProfileRetries
/**
* Executes profile retries.
*
* @param {ProfileSettings} profile Settings of channel.
* @param {object[]} savedMessages Messages stored in cache.
* @param {object} message Message sent by the bridge.
* @param {ResponseMessage} response Default response.
* @param {ProfileData} profileData Profile data
* @returns {ResponseResult} Response result.
*/
private executeProfileRetries(
profile: ProfileSettings,
savedMessages: any[],
message: any,
response: ResponseMessage,
profileData: ProfileData
): ResponseResult {
Example
this.executeProfileRetries(profile, [{text: 'hola'}], 'hola', response, profileData);
executeProfileTokenExpired
/**
* Execute `tokenExpired` profile.
* Emulate the `token expired` response from 4P.
*
* @param {any} message Message sent by the bridge.
* @returns {ResponseResult} Response result.
*/
private executeProfileTokenExpired(message: any): ResponseResult {
getNamespaceAndProfile
/**
* Get namespace and profile from value.
* Example: '12345|namespace:aura-ap-next|retries:wa-1015&4p-200' => { namespace: 'aura', profile: '12345|retries:wa-1015&4p-200' }
*
* @param {string} value Value to test
* @returns {{ namespace: string, profile: string }} Namespace and profile
*/
public getNamespaceAndProfile(value: string): { namespace: string, profile: string } {
Example
const { namespace, profile } = services.profileService.getNamespaceAndProfile(id);
2.12 - redis-service plugin
aura-mocks-redis-service plugin
Module that connect plugins to Redis database
Description
aura-mocks-redis-service plugin is a tool using aura-redis-handler that allows the connection of plugins to Redis database.
Find more information in the Github repository:
https://github.com/Telefonica/aura-mocks-server/tree/master/src/plugins/aura-mocks-redis-service
This is part of aura-mocks-server project.
Methods
delete
Delete element by key from Redis.
| Property |
Type |
Description |
| pattern |
string |
Unique key for Redis |
| corr |
string |
Unique correlator |
Example:
await redisService.delete('test-key', 'test-correlator');
get
Get element by key from Redis.
| Property |
Type |
Description |
| pattern |
string |
Unique key for Redis |
| corr |
string |
Unique correlator |
Example:
await redisService.get('test-key', 'test-correlator');
info
Return info from Redis.
| Property |
Type |
Description |
| sections |
string[]/undefined |
Array with sections |
| corr |
string |
Unique correlator |
Example:
await redisService.info(['section_1'], 'test-correlator');
lPush
Put an element at the beginning of a Redis list.
| Property |
Type |
Description |
| pattern |
string |
Unique key for Redis |
| value |
string |
Data to save |
| corr |
string |
Unique correlator |
Example:
await redisService.lPush('test-key', 'data', 'test-correlator');
rPush
Put an element at the end of a Redis list.
| Property |
Type |
Description |
| pattern |
string |
Unique key for Redis |
| value |
string |
Data to save |
| corr |
string |
Unique correlator |
Example:
await redisService.rPush('test-key', 'data', 'test-correlator');
lRange
Get elements by key and range from Redis list.
| Property |
Type |
Description |
| pattern |
string |
Unique key for Redis |
| from |
number |
Start index |
| to |
number |
End index |
| corr |
string |
Unique correlator |
Example:
await redisService.lRange('test-key', 0, 10, 'test-correlator');
set
Add data by key to Redis.
| Property |
Type |
Description |
| pattern |
string |
Unique key for Redis |
| value |
string |
Data to save |
| corr |
string |
Unique correlator |
Example:
await redisService.set('test-key', 'data', 'test-correlator');
sAdd
Add element to the set of Redis.
| Property |
Type |
Description |
| pattern |
string |
Unique key for Redis |
| value |
string |
Data to save |
| corr |
string |
Unique correlator |
Example:
await redisService.sAdd('test-key', 'data', 'test-correlator');
sInter
Get elements by key Redis.
| Property |
Type |
Description |
| pattern |
string |
Unique key for Redis |
| corr |
string |
Unique correlator |
Example:
await redisService.sInter('test-key', 'data', 'test-correlator');
sRem
Remove element from the set of Redis.
| Property |
Type |
Description |
| pattern |
string |
Unique key for Redis |
| value |
string |
Value to search |
| corr |
string |
Unique correlator |
Example:
await redisService.sRem('test-key', 'data', 'test-correlator');
zAdd
Add element to the sorted set.
| Property |
Type |
Description |
| pattern |
string |
Unique key for Redis |
| score |
number |
Index of the element |
| value |
string |
Value to add |
| corr |
string |
Unique correlator |
Example:
await redisService.zAdd('test-key', 'data', 'test-correlator');
zRevRange
Get elements by key and range.
| Property |
Type |
Description |
| pattern |
string |
Unique key for Redis |
| from |
string/number |
Start index |
| to |
string/number |
End index |
| corr |
string |
Unique correlator |
Example:
await redisService.zRevRange('test-key', 0, 10, 'test-correlator');
withLock
Lock Redis key and execute function.
| Property |
Type |
Description |
| fn |
function |
Callback |
| key |
string |
Key to lock |
| corr |
string |
Unique correlator |
Example:
await redisService.withLock(await () => true, 'test-key', 'test-correlator');
2.13 - send-feedback-api plugin
aura-mocks-send-feedback-api plugin
Plugin that mocks feedback sent by *aura-bridge
Description
The aura-mocks-send-feedback-api plugin simulates the server that is responsible for receiving the different requests from the aurapush-sendfeedback-service plugin of *aura-bridge component. These requests may involve the sending of statues, errors o messages.
Find more information in the Github repository:
https://github.com/Telefonica/aura-mocks-server/tree/master/src/plugins/aura-mocks-send-feedback-api
This is part of aura-mocks-server project.
Endpoints API
| Enpoint |
Method |
Group |
description |
| /feedback/statuses/update |
PUT |
Send Feedback |
Update statuses |
| /feedback/errors/update |
PUT |
Send Feedback |
Update errors |
| /feedback/messages/update |
PUT |
Send Feedback |
Update messages |
| /feedback/messages |
DELETE |
Send Feedback |
Delete cache |
| /feedback/messages/:messageId |
GET |
Send Feedback |
Get message feedback by MessageId |
| /feedback/messages |
GET |
Send Feedback |
Get all message feedback |
PUT: /feedback/statuses/update
Update statuses by messageId, so messageId is mandatory.
PUT: /feedback/errors/update
Update errors by messageId, so messageId is mandatory.
PUT: /feedback/messages/update
Update messages by messageId, so messageId is mandatory.
DELETE: /feedback/messages/
Delete feedback message by messageId. The query param messageId is mandatory.
GET: /feedback/messages/
Get all messages feedback by MessageId. The query messageId value is mandatory.
GET: /feedback/messages/:messageId
Get message feedback by MessageId. The property in body messageId is mandatory.
2.14 - sms-soap-service plugin
aura-mocks-sms-soap-service plugin
Description of the aura-mocks-sms-soap-service plugin
Description
The aura-mocks-sms-soap-service** plugin is responsible for providing a mock SOAP service with access to a test bot dialog: sms-soap-service-dialog.
Find more information in the Github repository:
https://github.com/Telefonica/aura-mocks-server/tree/master/src/plugins/aura-mocks-sms-soap-service
This is part of aura-mocks-server project.
Endpoints API
| Enpoint |
Method |
Group |
description |
| /sms |
GET |
soap |
Soap Service with operation: sendSMS |
Variables
| name |
type |
description |
mandatory |
| AURA_MOCKS_SOAP_ACTIVE |
string |
Flag to indicate if SOAP service is active. By default: false. |
false |
| AURA_MOCKS_SOAP_SERVER_URI |
string |
URI for SOAP service used to define wsdl. By default: http://localhost:3000. |
false |
2.15 - storage-file-manager plugin
aura-mocks-storage-file-manager plugin
Description of the aura-mocks-storage-file-manager plugin
Description
The aura-mocks-storage-file-manager plugin is responsible for providing access to the aura-storage-file-manager utility to upload and download files from an Azure Storage account.
Find more information in the Github repository:
https://github.com/Telefonica/aura-mocks-server/tree/master/src/plugins/aura-mocks-storage-file-manager
This is part of aura-mocks-server project.
Variables
| name |
type |
description |
mandatory |
| AURA_MOCKS_MICROSOFT_AZURE_STORAGE_ACCESS_KEY |
string |
Azure storage access key |
yes |
| AURA_MOCKS_MICROSOFT_AZURE_STORAGE_ACCOUNT |
string |
Azure storage account |
yes |
| AURA_MOCKS_AZURE_STORAGE_CONTAINER |
string |
Container where mocks resources are stored. By default: aura-mocks-server |
no |
2.16 - store-activities-api plugin
aura-mocks-store-activities-api plugin
Plugin that mocks sending activities* of aura-bot*
Description
The aura-mocks-store-activities-api plugin simulates sending activities messages with several useful endpoints for the QA team and performance testing.
Find more information in the Github repository:
https://github.com/Telefonica/aura-mocks-server/tree/master/src/plugins/aura-mocks-store-activities-api
This is part of aura-mocks-server project.
Endpoints API
| Enpoint |
Method |
Group |
description |
| /activities |
GET |
bot |
Get messages |
| /v3/conversations/:conversationId/activities/:activityId |
POST |
bot |
Delete messages |
GET: /activities
Get message by activityCorrelator. The query param activityCorrelator is mandatory.
POST: /v3/conversations/:conversationId/activities/:activityId
Add activities.
POST: /api/messages
Add new activity message.
{
"type": "Receive_Message",
"activity": {
"type": "message",
"id": "DF8d619NDYp3ywW1ew9QFK-fr|0000003",
"timestamp": "2022-05-23T14:59:52.0129204Z",
"channelId": "directline",
"from": {
"id": "BOT-aura-ap-next",
"name": "BOT-aura-ap-next"
},
"conversation": {
"id": "DF8d619NDYp3ywW1ew9QFK-fr"
},
"attachmentLayout": "list",
"text": "Fiquei com dúvida. Veja se uma dessas respostas pode ajudar:",
"speak": "Fiquei com dúvida. Veja se uma dessas respostas pode ajudar:",
"inputHint": "expectingInput",
"attachments": [
{
"contentType": "application/vnd.microsoft.card.hero",
"content": {
"buttons": [
{
"type": "imBack",
"title": "Canonic phrase for intent:intent.bundle.get_name_by_type",
"value": "Canonic phrase for intent:intent.bundle.get_name_by_type"
},
{
"type": "imBack",
"title": "Canonic phrase for intent:intent.common.greetings",
"value": "Canonic phrase for intent:intent.common.greetings"
},
{
"type": "imBack",
"title": "¿Cómo puedo acceder a Mi Movistar?",
"value": "¿Cómo puedo acceder a Mi Movistar?"
}
]
}
}
],
"channelData": {
"hasMoreMessages": false,
"correlator": "6ed5ed79-cd88-415e-9135-654417fef9b6"
},
"replyToId": "DF8d619NDYp3ywW1ew9QFK-fr|0000002"
}
}
2.17 - whatsapp-api plugin
aura-mocks-whatsapp-api plugin
Plugin that mocks WhatsApp.
Description
The aura-mocks-whatsapp-api plugin simulates aura-bridge for aura-bot WhatsApp callbacks and adds several useful endpoints for the QA team and performance testing.
Find more information in the Github repository:
https://github.com/Telefonica/aura-mocks-server/tree/master/src/plugins/aura-mocks-whatsapp-api
This is part of aura-mocks-server project.
Endpoints API
| Enpoint |
Method |
Group |
description |
| /whatsapp/messages |
GET |
Whatsapp |
Get messages |
| /whatsapp/messages |
POST |
Whatsapp |
Add new message |
| /whatsapp/messages |
DELETE |
Whatsapp |
Delete messages |
| /whatsapp/messages/:id |
PUT |
Whatsapp |
Add new read message |
| /whatsapp/read-messages |
GET |
Whatsapp |
Get read messages |
| /whatsapp/read-messages |
POST |
Whatsapp |
Add new read message |
| /whatsapp/read-messages |
DELETE |
Whatsapp |
Delete readmessages |
| /whatsapp/no-notification/messages |
POST |
Whatsapp |
Add new message |
| /whatsapp/no-notification/messages/:id |
PUT |
Whatsapp |
Add new read message |
| /whatsapp/4p/:error/messages |
POST |
Whatsapp |
Add new message and return error |
| /whatsapp/4p/:error/messages/:id |
PUT |
Whatsapp |
Add new read message |
| /whatsapp/:error/messages |
POST |
Whatsapp |
Add new message and return error |
| /whatsapp/:error/messages/:id |
PUT |
Whatsapp |
Add new read message |
GET: /whatsapp/messages
Get messages from WhatsApp. The query param to is mandatory.
POST: /whatsapp/messages
Add new message for WhatsApp.
{
"to": "34666666660",
"text": "Testing POST /whatsapp/messages"
}
DELETE: /whatsapp/messages
Delete messages from WhatsApp. The query param to is mandatory.
PUT: /whatsapp/messages/:id
Add new read message for WhatsApp.
{
"to": "34666666660",
"text": "Testing PUT /whatsapp/messages/:id"
}
GET: /whatsapp/read-messages
Get read messages from WhatsApp. The query param to is mandatory.
POST: /whatsapp/read-messages
Add new read message for WhatsApp.
{
"to": "34666666660",
"text": "Testing POST /whatsapp/read-messages"
}
DELETE: /whatsapp/read-messages
Delete read messages from WhatsApp. The query param to is mandatory.
POST: /whatsapp/no-notification/messages
Add new message for WhatsApp.
{
"to": "34666666660",
"text": "Testing POST /whatsapp/no-notification/messages"
}
PUT: /whatsapp/no-notification/messages/:id
Add new read message for WhatsApp.
{
"to": "34666666660",
"text": "Testing PUT /whatsapp/no-notification/messages/:id"
}
POST: /whatsapp/4p/:error/messages
Add new message and return status code error.
{
"to": "34666666660",
"text": "Testing POST /whatsapp/4p/:error/messages"
}
PUT: /whatsapp/4p/:error/messages/:id
Add new read message for WhatsApp.
{
"to": "34666666660",
"text": "Testing PUT /whatsapp/4p/:error/messages/:id"
}
POST: /whatsapp/:error/messages
Add new message and return status code error and error message.
{
"to": "34666666660",
"text": "Testing POST /whatsapp/:error/messages"
}
PUT: /whatsapp/:error/messages/:id
Add new read message for WhatsApp.
{
"to": "34666666660",
"text": "Testing PUT /whatsapp/:error/messages/:id"
}