Skip to content

Commit 38f7e2b

Browse files
added Send Message macro sample
1 parent ac2f8cd commit 38f7e2b

2 files changed

Lines changed: 30 additions & 4 deletions

File tree

controls/score/score.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
<Name>Instructions</Name>
4848
<Widget>
4949
<WidgetId>rules</WidgetId>
50-
<Name>Navigate around the maze and find the treasure. Press help to show the map, note that it will cost you 500 points every time you ask for it. Here are the symbols displayed on the map. </Name>
50+
<Name>Navigate around the maze and find the treasure. Press help to show the map, note that it will cost you 500 points every time you ask for it.</Name>
5151
<Type>Text</Type>
5252
<Options>size=4;fontSize=small</Options>
5353
</Widget>
@@ -115,10 +115,10 @@
115115
<Row>
116116
<Name>About</Name>
117117
<Widget>
118-
<WidgetId>widget_1</WidgetId>
119-
<Name>by @SteveSfartz (Cisco DevNet)</Name>
118+
<WidgetId>about</WidgetId>
119+
<Name>v1.0.0, by @SteveSfartz (https://developer.cisco.com)</Name>
120120
<Type>Text</Type>
121-
<Options>size=4;align=center;fontSize=small</Options>
121+
<Options>size=4;align=left;fontSize=small</Options>
122122
</Widget>
123123
</Row>
124124
<Options>hideRowNames=0</Options>

macros/8-message.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Illustrates how to pass messages among macros, or to external APIs (via HTTP Feedback)
3+
*/
4+
5+
const xapi = require('xapi');
6+
7+
xapi.event.on("Message Send Text", (text) => {
8+
// Decode (from naive implementation) and deserialize
9+
let decoded = text.replace(/\'/g, '"')
10+
let data = JSON.parse(decoded)
11+
12+
console.log(`Received score: ${data.score}, for player: ${data.player}`)
13+
})
14+
15+
16+
let data = {
17+
score : 5,
18+
player : "Stève"
19+
}
20+
21+
// Serialize and encode
22+
// [WORKAROUND] as Duktape does not provide encoders, provide a naive implementation
23+
const serialized = JSON.stringify(data)
24+
const encoded = serialized.replace(/"/g, "\'")
25+
26+
xapi.command("Message Send", { Text: encoded })

0 commit comments

Comments
 (0)