44 "time"
55
66 "go.uber.org/cadence/workflow"
7+ "go.uber.org/cadence/x/blocks"
78 "go.uber.org/zap"
89)
910
@@ -16,39 +17,6 @@ const ApplicationName = "blocksGroup"
1617
1718const blocksWorkflowName = "blocksWorkflow"
1819
19- // Query response structures
20- type LunchQueryResponse struct {
21- CadenceResponseType string `json:"cadenceResponseType"`
22- Format string `json:"format"`
23- Blocks []Block `json:"blocks"`
24- }
25-
26- type Block struct {
27- Type string `json:"type"`
28- Format string `json:"format,omitempty"`
29- ComponentOptions * ComponentOptions `json:"componentOptions,omitempty"`
30- Elements []Element `json:"elements,omitempty"`
31- }
32-
33- type Element struct {
34- Type string `json:"type"`
35- ComponentOptions * ComponentOptions `json:"componentOptions,omitempty"`
36- Action * Action `json:"action,omitempty"`
37- }
38-
39- type ComponentOptions struct {
40- Type string `json:"type,omitempty"`
41- Text string `json:"text,omitempty"`
42- }
43-
44- type Action struct {
45- Type string `json:"type"`
46- SignalName string `json:"signal_name,omitempty"`
47- SignalValue interface {} `json:"signal_value,omitempty"`
48- WorkflowID string `json:"workflow_id,omitempty"`
49- RunID string `json:"run_id,omitempty"`
50- }
51-
5220// This is an example of using the 'blocks' query response in a cadence query, in this example,
5321// to select the lunch option.
5422func blocksWorkflow (ctx workflow.Context , name string ) error {
@@ -63,81 +31,11 @@ func blocksWorkflow(ctx workflow.Context, name string) error {
6331
6432 votes := []map [string ]string {}
6533
66- workflow .SetQueryHandler (ctx , "options" , func () (LunchQueryResponse , error ) {
34+ workflow .SetQueryHandler (ctx , "options" , func () (blocks. QueryResponse , error ) {
6735 logger := workflow .GetLogger (ctx )
6836 logger .Info ("Responding to 'options' query" )
6937
70- return LunchQueryResponse {
71- CadenceResponseType : "formattedData" ,
72- Format : "blocks" ,
73- Blocks : []Block {
74- {
75- Type : "section" ,
76- Format : "text/markdown" ,
77- ComponentOptions : & ComponentOptions {
78- Text : "## Lunch options\n We're voting on where to order lunch today. Select the option you want to vote for." ,
79- },
80- },
81- {
82- Type : "divider" ,
83- },
84- {
85- Type : "section" ,
86- Format : "text/markdown" ,
87- ComponentOptions : & ComponentOptions {
88- Text : makeVoteTable (votes ),
89- },
90- },
91- {
92- Type : "section" ,
93- Format : "text/markdown" ,
94- ComponentOptions : & ComponentOptions {
95- Text : makeMenu (),
96- },
97- },
98- {
99- Type : "actions" ,
100- Elements : []Element {
101- {
102- Type : "button" ,
103- ComponentOptions : & ComponentOptions {
104- Type : "plain_text" ,
105- Text : "Farmhouse" ,
106- },
107- Action : & Action {
108- Type : "signal" ,
109- SignalName : "lunch_order" ,
110- SignalValue : map [string ]string {"location" : "farmhouse - red thai curry" , "requests" : "spicy" },
111- },
112- },
113- {
114- Type : "button" ,
115- ComponentOptions : & ComponentOptions {
116- Type : "plain_text" ,
117- Text : "Ethiopian" ,
118- },
119- Action : & Action {
120- Type : "signal" ,
121- SignalName : "no_lunch_order_walk_in_person" ,
122- WorkflowID : "in-person-order-workflow" ,
123- },
124- },
125- {
126- Type : "button" ,
127- ComponentOptions : & ComponentOptions {
128- Type : "plain_text" ,
129- Text : "Ler Ros" ,
130- },
131- Action : & Action {
132- Type : "signal" ,
133- SignalName : "lunch_order" ,
134- SignalValue : map [string ]string {"location" : "Ler Ros" , "meal" : "tofo Bahn Mi" },
135- },
136- },
137- },
138- },
139- },
140- }, nil
38+ return makeResponse (votes ), nil
14139 })
14240
14341 votesChan := workflow .GetSignalChannel (ctx , "lunch_order" )
@@ -162,6 +60,21 @@ func blocksWorkflow(ctx workflow.Context, name string) error {
16260 return nil
16361}
16462
63+ // makeResponse creates the lunch query response payload based on the current votes
64+ func makeResponse (votes []map [string ]string ) blocks.QueryResponse {
65+ return blocks .New (
66+ blocks .NewMarkdownSection ("## Lunch options\n We're voting on where to order lunch today. Select the option you want to vote for." ),
67+ blocks .NewDivider (),
68+ blocks .NewMarkdownSection (makeVoteTable (votes )),
69+ blocks .NewMarkdownSection (makeMenu ()),
70+ blocks .NewSignalActions (
71+ blocks .NewSignalButton ("Farmhouse" , "lunch_order" , map [string ]string {"location" : "farmhouse - red thai curry" , "requests" : "spicy" }),
72+ blocks .NewSignalButtonWithExternalWorkflow ("Ethiopian" , "no_lunch_order_walk_in_person" , nil , "in-person-order-workflow" , "" ),
73+ blocks .NewSignalButton ("Ler Ros" , "lunch_order" , map [string ]string {"location" : "Ler Ros" , "meal" : "tofo Bahn Mi" }),
74+ ),
75+ )
76+ }
77+
16578func makeMenu () string {
16679
16780 options := []struct {
0 commit comments