forked from GATERAGE/nodeengine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevaluate_continue.py
81 lines (68 loc) · 2.24 KB
/
evaluate_continue.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# Copyright (c) Microsoft. All rights reserved.
import asyncio
from node_engine.libs.node_engine_component import NodeEngineComponent
from node_engine.models.flow_step import FlowStep
class EvaluateContinue(NodeEngineComponent):
description = "Evaluate whether the flow should continue or not. This is just a sample component to demonstrate the ability to perform flow control within a flow."
reads_from = {
"context": {
"continued": {
"type": "boolean",
"description": "Whether the flow should continue or not.",
"required": False,
}
},
}
writes_to = None
sample_input = {
"key": "sample",
"session_id": "123456",
"context": {
"continued": True,
},
"flow": [
{
"key": "start",
"name": "EvaluateContinue",
"config": {
"outputs": {
"yes": "event_continue",
"no": "event_stop",
},
},
},
{
"key": "event_continue",
"name": "EmitEvents",
"config": {
"events": [
{
"event": "continue",
},
],
},
},
{
"key": "event_stop",
"name": "EmitEvents",
"config": {
"events": [
{
"event": "stop",
},
],
},
},
],
}
async def execute(self) -> FlowStep:
# extract intent from message
outputs = self.config.get("outputs")
if not outputs:
return self.exit_flow_with_error("outputs not found in component config")
# Simulate some processing time
await asyncio.sleep(1)
continued = self.context.get("continued", False)
next = outputs["yes"] if continued else outputs["no"]
self.log("Evaluating continue: {}".format(continued))
return self.continue_flow(next)