Swimming and biking activity details missing in aggregate api - google-fit

We are building application which requires integration with Google Fit Rest API. The requirement is to get detailed data of each activity of user. Currently, we can get activity details of user by calling "https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate" api with dataTypeName as "com.google.activity:segment". The api response only returns duration of activity instead of metric details like Calories, Distance etc.
In the response below, we have 2 activities 1 -> Biking, 82 -> Swimming being returned from request, however, the only metrics it contains is duration of Activity. Is there any api which can return calories burnt, distance covered for these set of activities?
Request:
{
"aggregateBy": [{
"dataTypeName": "com.google.activity.segment"
}],
"bucketByTime": { "durationMillis": 86400000 },
"startTimeMillis": 1591117200000,
"endTimeMillis": 1591203599999
}
Response:
{
"bucket": [
{
"startTimeMillis": "1591117200000",
"endTimeMillis": "1591203599999",
"dataset": [
{
"dataSourceId": "derived:com.google.activity.summary:com.google.android.gms:aggregated",
"point": [
{
"startTimeNanos": "1591198680000000000",
"originDataSourceId": "raw:com.google.activity.segment:com.google.android.apps.fitness:user_input",
"endTimeNanos": "1591200480000000000",
"value": [
{
"mapVal": [],
"intVal": 1
},
{
"mapVal": [],
"intVal": 1800000
},
{
"mapVal": [],
"intVal": 1
}
],
"dataTypeName": "com.google.activity.summary"
},
{
"startTimeNanos": "1591191540000000000",
"originDataSourceId": "raw:com.google.activity.segment:com.google.android.apps.fitness:user_input",
"endTimeNanos": "1591193340000000000",
"value": [
{
"mapVal": [],
"intVal": 82
},
{
"mapVal": [],
"intVal": 1800000
},
{
"mapVal": [],
"intVal": 1
}
],
"dataTypeName": "com.google.activity.summary"
}
]
}
]
}
]
}

Related

REST API 400 Bad Request for Aggregated Activity Segments on Empty Data

We’re requesting activity data aggregated by segments for our users via REST interface.
But for some users (not all), retrieving this data fails with a 400 Bad Request despite sharing the same request format.
An example request JSON to aggregate by segments is:
{
"aggregateBy": [
{
"dataTypeName": "com.google.activity.segment"
},
{
"dataTypeName": "com.google.calories.expended"
},
{
"dataTypeName": "com.google.step_count.delta"
}
],
"bucketByActivitySegment": {
"minDurationMillis": 60000
},
"startTimeMillis": 1627182120000,
"endTimeMillis": 1627268520000
}
For all users with recorded activity data, we receive successful responses with data points, like for example:
{
"bucket": [
{
"startTimeMillis": "1627180684015",
"endTimeMillis": "1627182139339",
"dataset": [
{
"dataSourceId": "derived:com.google.activity.summary:com.google.android.gms:aggregated",
"point": [
{
"startTimeNanos": "1627180684015000000",
"endTimeNanos": "1627182139339000000",
"dataTypeName": "com.google.activity.summary",
"originDataSourceId": "derived:com.google.activity.segment:com.google.android.gms:merge_activity_segments",
"value": [
{
"intVal": 7,
"mapVal": []
},
{
"intVal": 1455324,
"mapVal": []
},
{
"intVal": 1,
"mapVal": []
}
]
}
]
},
[...]
But for users with no recorded activity data, we always receive 400 Bad Request responses, like:
{
"error": {
"code": 400,
"message": "unknown datasource: derived:com.google.activity.segment:com.google.android.gms:merge_activity_segments",
"errors": [
{
"message": "unknown datasource: derived:com.google.activity.segment:com.google.android.gms:merge_activity_segments",
"domain": "global",
"reason": "invalidArgument"
}
],
"status": "INVALID_ARGUMENT"
}
}
We confirmed that there is no recorded activity data by aggregating activity data by time, e.g. the request
{
"aggregateBy": [
{
"dataTypeName": "com.google.activity.segment"
}
],
"bucketByTime": {
"durationMillis": 60000
},
"startTimeMillis": 1627182120000,
"endTimeMillis": 1627268520000
}
leads to a successful response with completely empty data points, like:
{
"bucket": [
{
"startTimeMillis": "1627182120000",
"endTimeMillis": "1627182180000",
"dataset": [
{
"dataSourceId": "derived:com.google.activity.summary:com.google.android.gms:aggregated",
"point": []
}
]
},
[...]
"dataset": [
{
"dataSourceId": "derived:com.google.activity.summary:com.google.android.gms:aggregated",
"point": []
}
]
}
]
}
Our questions are:
Is the 400 Bad Request response actually avoidable for users with empty data?
Or should this be considered a bug in the Google Fit API? We don't see a reason to respond with a 400 Bad Request instead of empty data when aggregating empty data by segments.
It was confirmed to us by the Google Fit team that this response behavior is not going to change, as users might already rely on it. We need to work around this, e.g. handle this error response separately, check if data is empty or something like this.

How to build a parent key based on a sub-string of another value using jq?

I'm re-shaping a JSON file which base content is the output of an AWS API call. From the raw output, I'm currently extracting the fields that I'm interested in the format I want except for a small detail that motivated this question.
Specifically, my input comes from the output of aws rds describe-db-instances command and contains the info of multiple RDS instances. Taking an example with 2 instances, this is how it looks:
{
"DBInstances": [
{
"DBInstanceIdentifier": "db1-name",
"DBInstanceClass": "db.m5.xlarge",
"Engine": "oracle-ee",
"DBInstanceStatus": "available",
"MasterUsername": "user",
"DBName": "RANDOM",
"Endpoint": {
"Address": "some-endpoint.rds.amazonaws.com",
"Port": 5698,
"HostedZoneId": "GHDSFHFSDHSDH"
},
"AllocatedStorage": 4000,
"InstanceCreateTime": "2018-07-23T23:21:42.361000+00:00",
"PreferredBackupWindow": "09:30-07:00",
"BackupRetentionPeriod": 14,
"DBSecurityGroups": [],
"VpcSecurityGroups": [
{
"VpcSecurityGroupId": "sg-xxxxxxxxxxxxxxxxx",
"Status": "active"
},
{
"VpcSecurityGroupId": "sg-xxxxxxxxxxxxxxxxx",
"Status": "active"
}
],
"DBParameterGroups": [
{
"DBParameterGroupName": "DB1-parameter",
"ParameterApplyStatus": "in-sync"
}
],
"AvailabilityZone": "ZONE1",
"DBSubnetGroup": {
"DBSubnetGroupName": "dbsubnetgroup-1",
"DBSubnetGroupDescription": "dbsubnetgroup-1",
"VpcId": "vpc-xxxxxxxxxxxxxxxxx",
"SubnetGroupStatus": "Complete",
"Subnets": [
{
"SubnetIdentifier": "subnet-xxxxxxxxxxxxxxxxx",
"SubnetAvailabilityZone": {
"Name": "az1"
},
"SubnetStatus": "Active"
},
{
"SubnetIdentifier": "subnet-xxxxxxxxxxxxxxxxx",
"SubnetAvailabilityZone": {
"Name": "az2"
},
"SubnetStatus": "Active"
}
]
},
"PreferredMaintenanceWindow": "sat:07:00-sat:07:30",
"PendingModifiedValues": {},
"LatestRestorableTime": "2020-03-27T18:54:25+00:00",
"MultiAZ": false,
"EngineVersion": "X.X.X",
"AutoMinorVersionUpgrade": false,
"ReadReplicaDBInstanceIdentifiers": [],
"LicenseModel": "bring-your-own-license",
"Iops": 5000,
"OptionGroupMemberships": [
{
"OptionGroupName": "optiongroupName",
"Status": "in-sync"
}
],
"CharacterSetName": "WE8ISO8859P15",
"PubliclyAccessible": false,
"StorageType": "io1",
"DbInstancePort": 0,
"StorageEncrypted": true,
"KmsKeyId": "someKey",
"DbiResourceId": "db-xxxxxxxxxxxxxxxxxxxxxxxxx",
"CACertificateIdentifier": "rds-ca-2019",
"DomainMemberships": [],
"CopyTagsToSnapshot": true,
"MonitoringInterval": 0,
"DBInstanceArn": "someARN",
"IAMDatabaseAuthenticationEnabled": false,
"PerformanceInsightsEnabled": false,
"DeletionProtection": false,
"AssociatedRoles": []
},
{
"DBInstanceIdentifier": "db2-name",
"DBInstanceClass": "db.m5.large",
"Engine": "oracle-ee",
"DBInstanceStatus": "available",
"MasterUsername": "user2",
"DBName": "XXXX",
"Endpoint": {
"Address": "endpoint2.rds.amazonaws.com",
"Port": 8974,
"HostedZoneId": "FASDFDS54FSA"
},
"AllocatedStorage": 100,
"InstanceCreateTime": "2020-04-23T21:38:53.023000+00:00",
"PreferredBackupWindow": "01:00-05:30",
"BackupRetentionPeriod": 35,
"DBSecurityGroups": [],
"VpcSecurityGroups": [
{
"VpcSecurityGroupId": "sg-xxxxxxxxxxxxxxxxx",
"Status": "active"
}
],
"DBParameterGroups": [
{
"DBParameterGroupName": "default",
"ParameterApplyStatus": "in-sync"
}
],
"AvailabilityZone": "AZ-2",
"DBSubnetGroup": {
"DBSubnetGroupName": "subnet-group",
"DBSubnetGroupDescription": "",
"VpcId": "vpc-xxxxxxxxxxxxxxxxx",
"SubnetGroupStatus": "Complete",
"Subnets": [
{
"SubnetIdentifier": "subnet-xxxxxxxxxxxxxxxxx",
"SubnetAvailabilityZone": {
"Name": "AZ-1"
},
"SubnetStatus": "Active"
},
{
"SubnetIdentifier": "subnet-xxxxxxxxxxxxxxxxx",
"SubnetAvailabilityZone": {
"Name": "AZ-2"
},
"SubnetStatus": "Active"
},
{
"SubnetIdentifier": "subnet-xxxxxxxxxxxxxxxxx",
"SubnetAvailabilityZone": {
"Name": "AZ-3"
},
"SubnetStatus": "Active"
}
]
},
"PreferredMaintenanceWindow": "sun:08:39-sun:09:09",
"PendingModifiedValues": {},
"LatestRestorableTime": "2020-07-27T18:53:18+00:00",
"MultiAZ": false,
"EngineVersion": "X.X.X",
"AutoMinorVersionUpgrade": false,
"ReadReplicaDBInstanceIdentifiers": [],
"LicenseModel": "bring-your-own-license",
"Iops": 2000,
"OptionGroupMemberships": [
{
"OptionGroupName": "optiongroup-name",
"Status": "in-sync"
}
],
"CharacterSetName": "AL32UTF8",
"PubliclyAccessible": false,
"StorageType": "io1",
"DbInstancePort": 0,
"StorageEncrypted": true,
"KmsKeyId": "someARN",
"DbiResourceId": "db-xxxxxxxxxxxxxxxxx",
"CACertificateIdentifier": "rds-ca-2019",
"DomainMemberships": [],
"CopyTagsToSnapshot": false,
"MonitoringInterval": 0,
"DBInstanceArn": "someARN",
"IAMDatabaseAuthenticationEnabled": false,
"PerformanceInsightsEnabled": false,
"DeletionProtection": false,
"AssociatedRoles": []
}
]
}
This is my current output:
[
{
"DBInstancePrefix": {
"DBInstanceClass": "db.m5.xlarge",
"DBInstanceIdentifier": "db1-name",
"DBName": "RANDOM",
"DBParameterGroupName": "DB1-parameter",
"DBSubnetGroupName": "dbsubnetgroup-1",
"KmsKeyId": "someKey",
"OptionGroupName": "optiongroupName",
"VpcSecurityGroupIds": [
"sg-xxxxxxxxxxxxxxxxx",
"sg-xxxxxxxxxxxxxxxxx"
]
}
},
{
"DBInstancePrefix": {
"DBInstanceClass": "db.m5.large",
"DBInstanceIdentifier": "db2-name",
"DBName": "XXXX",
"DBParameterGroupName": "default",
"DBSubnetGroupName": "subnet-group",
"KmsKeyId": "someARN",
"OptionGroupName": "optiongroup-name",
"VpcSecurityGroupIds": [
"sg-xxxxxxxxxxxxxxxxx"
]
}
}
]
This is my current JQ filter:
. | [.[] | map(.) | .[] | {DBInstancePrefix: {DBInstanceClass: .DBInstanceClass, DBInstanceIdentifier: .DBInstanceIdentifier, DBName: .DBName, DBParameterGroupName:.DBParameterGroups[].DBParameterGroupName, DBSubnetGroupName: .DBSubnetGroup.DBSubnetGroupName, KmsKeyId:.KmsKeyId, OptionGroupName: .OptionGroupMemberships[].OptionGroupName, VpcSecurityGroupIds: [.VpcSecurityGroups | .[] | .VpcSecurityGroupId] }}]
You can verify it on this snippet on jqplay.org.
What I need is to turn the parent key "DBInstancePrefix" dynamic based on a substring from "DBInstanceIdentifier" key. So for the example names I wrote would be:
"db1-name" >>> "db1"
"db2-name" >>> "db2"
So, my desired output would be:
[
{
"db1": {
"DBInstanceClass": "db.m5.xlarge",
"DBInstanceIdentifier": "db1-name",
"DBName": "RANDOM",
"DBParameterGroupName": "DB1-parameter",
"DBSubnetGroupName": "dbsubnetgroup-1",
"KmsKeyId": "someKey",
"OptionGroupName": "optiongroupName",
"VpcSecurityGroupIds": [
"sg-xxxxxxxxxxxxxxxxx",
"sg-xxxxxxxxxxxxxxxxx"
]
}
},
{
"db2": {
"DBInstanceClass": "db.m5.large",
"DBInstanceIdentifier": "db2-name",
"DBName": "XXXX",
"DBParameterGroupName": "default",
"DBSubnetGroupName": "subnet-group",
"KmsKeyId": "someARN",
"OptionGroupName": "optiongroup-name",
"VpcSecurityGroupIds": [
"sg-xxxxxxxxxxxxxxxxx"
]
}
}
]
Any ideas or suggestions? Thanks for reading.
To manipulate the object key-name as you desire, you can apply the filter operation inside (..). Any operation done inside it, the result is preserved "literally".
Your case demands the DBInstanceIdentifier to be split by - and using the first element in the resultant array.
With that and few other trivial modifications, you need
.DBInstances |
map
(
{
( .DBInstanceIdentifier | split("-")[0] ): {
DBInstanceClass,
DBInstanceIdentifier,
DBName,
DBParameterGroupName:.DBParameterGroups[].DBParameterGroupName,
DBSubnetGroupName: .DBSubnetGroup.DBSubnetGroupName,
KmsKeyId,
OptionGroupName: .OptionGroupMemberships[].OptionGroupName,
VpcSecurityGroupIds: [.VpcSecurityGroups[] | .VpcSecurityGroupId ]
}
}
)
jqplay - Demo
I took the long path and since I couldn't resolve it on the same filter I did another one that takes the output of the first one and thus achieved the desired result. But it is awful compared with the answer selected as the solution.
Based on Inian answer, I did a small modification since my real DBInstanceIdentifier values have the following format:
<name>-db-<environment> and I need DBInstancePrefix becomes <name>-db.
So, my final filter is:
.DBInstances |
map
(
{
( .DBInstanceIdentifier|split("-")[0:2] | join("-") ): {
DBInstanceClass,
DBInstanceIdentifier,
DBName,
DBParameterGroupName:.DBParameterGroups[].DBParameterGroupName,
DBSubnetGroupName: .DBSubnetGroup.DBSubnetGroupName,
KmsKeyId,
OptionGroupName: .OptionGroupMemberships[].OptionGroupName,
VpcSecurityGroupIds: [.VpcSecurityGroups[] | .VpcSecurityGroupId ]
}
}
)

Fetching for each element within array in MongoDb

I have an 'users' collection. I store id's of users I follow in 'following' field.
{
"_id": {
"$oid": "5eab360253ec352e3cc791d6"
},
"email": "koray#gmail.com",
"password": "81dc9bdb52d04dc20036dbd8313ed055",
"following": ["5ea8879dfc286e1154a866cb", "5ea8879dfc286e1154a866c"],
"posts": [{
"head": "deneme header",
"body": "deneme body",
"is_private": false
}]
}
I want to get posts of users I follow as well as posts belogs to me but can't manage to pull it off.
You can use $lookup with custom pipeline and fetch documents from the same collection:
db.collection.aggregate([
{ $match: { _id: "5eab360253ec352e3cc791d6" } },
{
$lookup: {
from: "collection",
let: { following_users: "$following" },
pipeline: [
{ $match: { $expr: { $in: [ "$_id", "$$following_users" ] } } },
{ $project: { posts: 1 } }
],
as: "following_posts"
}
}
])
Mongo Playground

How to decode Logs and get back Events with web3?

I have this transaction that emits 2 different events from 2 different contracts. Let's say I have the ABI files for both contracts, how can I parse the events out of the logs field?
For example, here is such transaction that emitted 2 events https://rinkeby.etherscan.io/tx/0xc6525195135a868897bd4c74ea0f6285b98492103be4df6fc5ea43f83b96b8eb#eventlog
And this is the respond of getTransactionReceipt RPC call, how can I parse the event names and their params out of the logs field?
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"blockHash": "0x3da27197fe084a82d76273b40c32e231d2662b229337795a43fde9f8d73b4d2c",
"blockNumber": "0x39a62b",
"contractAddress": null,
"cumulativeGasUsed": "0x48ad9",
"from": "0x20b53b91da0a2d9afdd442b2bb433a40ab7f9613",
"gasUsed": "0x9e36",
"logs": [
{
"address": "0x5328276603d169165d0f71ca67ccc89c45027df3",
"blockHash": "0x3da27197fe084a82d76273b40c32e231d2662b229337795a43fde9f8d73b4d2c",
"blockNumber": "0x39a62b",
"data": "0x000000000000000000000000f63843b0b7fc5097bc1f92658379617513cce546000000000000000000000000ff0e3299e55efd859176d582fc805481e83449150000000000000000000000000000000000000000000000000000000000002245",
"logIndex": "0x1",
"removed": false,
"topics": [
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"
],
"transactionHash": "0x5442a15c593b3fcf3069ad7f6a41d8805a66a49ed407d872e46ea95b1c9f6054",
"transactionIndex": "0x3"
},
{
"address": "0x7387e0b25165e9a621f624e47b3362a937892c7b",
"blockHash": "0x3da27197fe084a82d76273b40c32e231d2662b229337795a43fde9f8d73b4d2c",
"blockNumber": "0x39a62b",
"data": "0x0000000000000000000000000000000000000000000000000000000000002245000000000000000000000000ff0e3299e55efd859176d582fc805481e8344915000000000000000000000000f63843b0b7fc5097bc1f92658379617513cce546000000000000000000000000000000000000000000000000016345785d8a0000000000000000000000000000000000000000000000000000000ffcb9e57d4000",
"logIndex": "0x2",
"removed": false,
"topics": [
"0x9accbcf984c4cd67a675ee4d38143974e1fa62aa95da283bd4ca645e408ec283"
],
"transactionHash": "0x5442a15c593b3fcf3069ad7f6a41d8805a66a49ed407d872e46ea95b1c9f6054",
"transactionIndex": "0x3"
}
],
"logsBloom": "0x20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000048000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000010000000000000000000000000000000000000000000000004000000000000000000080000008000000000000000000000000000000000000000400000000000000000000000000002000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"status": "0x1",
"to": "0x7387e0b25165e9a621f624e47b3362a937892c7b",
"transactionHash": "0x5442a15c593b3fcf3069ad7f6a41d8805a66a49ed407d872e46ea95b1c9f6054",
"transactionIndex": "0x3"
}
}

Set next step for the waterfall dialogue in Microsoft BotBuilder NodeJS SDK

I am using Microsoft Bot Framework for my facebook messenger bot. I want to load the dialog data from json files instead of hard coding in the js file. I would like to configure the next step in the dialog, based on result from the "current" step, which is part of the json file configuration, something like this.
{
"name": "welcome",
"type": "waterfall",
"steps": [
{
"id": 0,
"data": [
{
"type": "text",
"value": "Hey, It's nice to meet you."
},
{
"type": "quickReplies",
"value": "What do you want to do next?",
"options": [
{
"text": "some option 1",
"value": "option1"
},
{
"text": "some option 2",
"value": "option2"
}
]
}
],
"next": [
{
"result": "option1",
"action": "goto step 2"
},
{
"result": "option2",
"action": "goto step 5"
}
]
}
]
}
I would like to process all the incoming messages and respond with correct dialog or correct step in the dialog for the user.
I am trying something like this;
handleMessage = function (session) {
var step = session.dialogData["BotBuilder.Data.WaterfallStep"] || 0;
// check response data from previou step and identify the next step.
// set the waterfall step id
session.dialogData["BotBuilder.Data.WaterfallStep"] = 2;
session.send("Hello");
}
var bot = new builder.UniversalBot(connector, function (session) {
handleMessage(session);
})
.set('storage',tableStorage);
With this code, I am always getting step as zero for session.dialogData["BotBuilder.Data.WaterfallStep"] even after setting this to a different number.
Also, as soon as I set the waterfall step number, all other state data that is stored in my table storage for this conversation is gone.
Storage data before setting waterfall step:
{
"BotBuilder.Data.SessionState": {
"callstack": [
{
"id": "*:/",
"state": {
"BotBuilder.Data.WaterfallStep": 0
}
},
{
"id": "*:welcome",
"state": {
"BotBuilder.Data.WaterfallStep": 1
}
},
{
"id": "BotBuilder:prompt-text",
"state": {
"options": {
"prompt": {
"type": "message",
"agent": "botbuilder",
"source": "facebook",
"address": {
"id": "mid.$cAAAlr-0LRH9niO21L1hV6hs83GuJ",
"channelId": "facebook",
"user": {
"id": "XXXX",
"name": "XXXX"
},
"conversation": {
"isGroup": false,
"id": "XX"
},
"bot": {
"id": "XXX",
"name": "XXX"
},
"serviceUrl": "https://facebook.botframework.com"
},
"text": "what do you want to next"
//ignored for simplicity
},
"promptAfterAction": true,
"libraryNamespace": "*"
},
"turns": 0,
"lastTurn": 1517594116372,
"isReprompt": false
}
}
],
"lastAccess": 1517594112740,
"version": 0
}
}
After I set the waterfall step:
{
"BotBuilder.Data.SessionState": {
"callstack": [
{
"id": "*:/",
"state": {
"BotBuilder.Data.WaterfallStep": 2
}
}
],
"lastAccess": 1517602122416,
"version": 0
}
}
Interestingly the step number is saved to the database (but in session state) but my "session" variable do not have this value anywhere. Also, even after configuring custom state service, the serviceUrl is still https://facebook.botframework.com which I thought is the default state service used if there is no state service set for the bot.
Per your code, as your bot actually contains only one waterfall step: handleMessage(session);, which raised your issue. You can consider to create multiple dialogs from json configration instead of complex waterfall steps.
Here is my quick test, for your information:
const json = `
[{
"name": "welcome",
"type": "waterfall",
"steps": [
{
"id": 0,
"data": [
{
"type": "text",
"value": "Hey, It's nice to meet you."
},
{
"type": "quickReplies",
"value": "What do you want to do next?",
"options": [
{
"text": "some option 1",
"value": "option1"
},
{
"text": "some option 2",
"value": "option2"
}
]
}
],
"next": [
{
"result": "option1",
"action": "dialog2"
},
{
"result": "option2",
"action": "dialog3"
}
]
}
]
},{
"name":"dialog2",
"type": "waterfall",
"steps": [
{
"data": [
{
"type": "text",
"value": "Hey, this is dialig2."
}]
}
]
},{
"name":"dialog3",
"type": "waterfall",
"steps": [
{
"data": [
{
"type": "text",
"value": "Hey, this is dialig3."
}]
}
]
}]
`;
const generateSignleStep = (step) => {
return (session, args, next) => {
step.forEach(sentence => {
switch (sentence.type) {
case 'quickReplies':
let choices = sentence.options.map(item => {
return item.value
});
let card = new builder.ThumbnailCard(session)
.text(sentence.value)
.buttons(sentence.options.map(choice => new builder.CardAction.imBack(session, choice.value, choice.text)))
let message = new builder.Message(session).addAttachment(card);
builder.Prompts.choice(session, message, choices);
break;
case 'text':
default:
session.send(sentence.value)
break;
}
})
}
}
const generatenextAction = (actions) => {
return (session, args, next) => {
const response = args.response;
actions.map(action => {
if (action.result == response.entity) {
session.beginDialog(action.action);
}
})
}
}
const generateWaterfallSteps = (steps) => {
let waterfall = [];
steps.forEach(step => {
waterfall.push(generateSignleStep(step.data));
if (step.next) {
waterfall.push(generatenextAction(step.next));
}
});
return waterfall;
}
var bot = new builder.UniversalBot(connector);
const jsonobj = JSON.parse(json);
jsonobj.forEach(dialog => {
bot.dialog(dialog.name, generateWaterfallSteps(dialog.steps))
.triggerAction({
matches: new RegExp(dialog.name, "g")
})
});
The result is: