From e0c410e1d93f7f6a02c1283e2113151c666cf7c6 Mon Sep 17 00:00:00 2001 From: cheetah Date: Wed, 2 Nov 2022 20:19:05 +0000 Subject: [PATCH] added examples --- examples/bash/emsg.sh | 44 ++++++++++++++++++++++++ examples/bash/filler.sh | 44 ++++++++++++++++++++++++ examples/bash/spamtest.sh | 72 +++++++++++++++++++++++++++++++++++++++ types/MessageManager.js | 10 +++--- 4 files changed, 166 insertions(+), 4 deletions(-) create mode 100644 examples/bash/emsg.sh create mode 100644 examples/bash/filler.sh create mode 100644 examples/bash/spamtest.sh diff --git a/examples/bash/emsg.sh b/examples/bash/emsg.sh new file mode 100644 index 0000000..3c87cf0 --- /dev/null +++ b/examples/bash/emsg.sh @@ -0,0 +1,44 @@ +#!/bin/bash +## Bash Library for sending out Pages and/or getting their State +# dependencies: curl, jq + +# echo "Bericht" | send_page "http://127.0.0.1:3000" "duplex" "birdyslim" "pocsag=133701A" +send_page() { + text=$(cat -) + endpoint=$1 + msgType=$2 + deviceType=$3 + argArr=("$@") + connectorJSON=$(for arg in "${argArr[@]}"; do echo $arg; done | jq -Rcs '{array:split("\n")|.[3:-1]|map(split("=")|[(.[0]),.[1]]?)}.array') + echo $connectorJSON |\ + jq -c --arg t "$msgType" --arg d "$deviceType" --arg p "$text" '{type:$t, routing: {connectors:.,device:$d}, payload:$p}' |\ + curl -s -XPOST -H "Content-type: application/json" "$endpoint/api/message/advanced" -d @- |\ + jq -r . +} + + +msg_status() { + endpoint=$1 + msgid=$2 + curl -s "$endpoint/api/message/status/$msgid" |\ + jq -r ._routerData +} +is_msg_recv() { + msg_status $* | jq .recvAck | grep -q "true" + return $? +} +is_msg_read() { + msg_status $* | jq .readAck | grep -q "true" + return $? +} +is_msg_resp() { + msg_status $* | jq .response | grep -vq "false" + return $? +} + +ENDPOINT="http://127.0.0.1:3000" +#echo "Test" | send_page "$ENDPOINT" "duplex" "birdyslim" "pocsag=133701D" "test=123" + + +echo "Testing API, respond with 1" | send_page "$ENDPOINT" "duplex" "emessage2WayS" "emessage=eCityruf#8907737" + diff --git a/examples/bash/filler.sh b/examples/bash/filler.sh new file mode 100644 index 0000000..993e2f6 --- /dev/null +++ b/examples/bash/filler.sh @@ -0,0 +1,44 @@ +#!/bin/bash +## Bash Library for sending out Pages and/or getting their State +# dependencies: curl, jq + +# echo "Bericht" | send_page "http://127.0.0.1:3000" "duplex" "birdyslim" "pocsag=133701A" +send_page() { + text=$(cat -) + endpoint=$1 + msgType=$2 + deviceType=$3 + argArr=("$@") + connectorJSON=$(for arg in "${argArr[@]}"; do echo $arg; done | jq -Rcs '{array:split("\n")|.[3:-1]|map(split("=")|[(.[0]),.[1]]?)}.array') + echo $connectorJSON |\ + jq -c --arg t "$msgType" --arg d "$deviceType" --arg p "$text" '{type:$t, routing: {connectors:.,device:$d}, payload:$p}' |\ + curl -s -XPOST -H "Content-type: application/json" "$endpoint/api/message/advanced" -d @- |\ + jq -r . +} + + +msg_status() { + endpoint=$1 + msgid=$2 + curl -s "$endpoint/api/message/status/$msgid" |\ + jq -r ._routerData +} +is_msg_recv() { + msg_status $* | jq .recvAck | grep -q "true" + return $? +} +is_msg_read() { + msg_status $* | jq .readAck | grep -q "true" + return $? +} +is_msg_resp() { + msg_status $* | jq .response | grep -vq "false" + return $? +} + +ENDPOINT="http://127.0.0.1:3000" +#echo "Test" | send_page "$ENDPOINT" "duplex" "birdyslim" "pocsag=133701D" "test=123" + + +echo "Empty" | send_page "$ENDPOINT" "simple" "birdyslim" "pocsag=80D" + diff --git a/examples/bash/spamtest.sh b/examples/bash/spamtest.sh new file mode 100644 index 0000000..f08db70 --- /dev/null +++ b/examples/bash/spamtest.sh @@ -0,0 +1,72 @@ +#!/bin/bash +## Bash Library for sending out Pages and/or getting their State +# dependencies: curl, jq + +# echo "Bericht" | send_page "http://127.0.0.1:3000" "duplex" "birdyslim" "pocsag=133701A" +send_page() { + text=$(cat -) + endpoint=$1 + msgType=$2 + deviceType=$3 + argArr=("$@") + connectorJSON=$(for arg in "${argArr[@]}"; do echo $arg; done | jq -Rcs '{array:split("\n")|.[3:-1]|map(split("=")|[(.[0]),.[1]]?)}.array') + echo $connectorJSON |\ + jq -c --arg t "$msgType" --arg d "$deviceType" --arg p "$text" '{type:$t, routing: {connectors:.,device:$d}, payload:$p}' |\ + curl -s -XPOST -H "Content-type: application/json" "$endpoint/api/message/advanced" -d @- |\ + jq -r . +} + + +msg_status() { + endpoint=$1 + msgid=$2 + curl -s "$endpoint/api/message/status/$msgid" |\ + jq -r ._routerData +} +is_msg_recv() { + msg_status $* | jq .recvAck | grep -q "true" + return $? +} +is_msg_read() { + msg_status $* | jq .readAck | grep -q "true" + return $? +} +is_msg_resp() { + msg_status $* | jq .response | grep -vq "false" + return $? +} + +ENDPOINT="http://127.0.0.1:3000" +#echo "Test" | send_page "$ENDPOINT" "duplex" "birdyslim" "pocsag=133701D" "test=123" + +echo -e "Test1234567890_1234567890_Testbericht13377777777777777777777777777777777777777777777777777777777777777777" | send_page "$ENDPOINT" "duplex" "birdyslim" "pocsag=133704A" +echo -e "Test1234567890_1234567890_Testbericht13377777777777777777777777777777777777777777777777777777777777777777" | send_page "$ENDPOINT" "duplex" "birdyslim" "pocsag=133704A" +echo -e "Test1234567890_1234567890_Testbericht13377777777777777777777777777777777777777777777777777777777777777777" | send_page "$ENDPOINT" "duplex" "birdyslim" "pocsag=133704A" +echo -e "Test1234567890_1234567890_Testbericht13377777777777777777777777777777777777777777777777777777777777777777" | send_page "$ENDPOINT" "duplex" "birdyslim" "pocsag=133704A" +echo -e "Test1234567890_1234567890_Testbericht13377777777777777777777777777777777777777777777777777777777777777777" | send_page "$ENDPOINT" "duplex" "birdyslim" "pocsag=133704A" +echo -e "Test1234567890_1234567890_Testbericht13377777777777777777777777777777777777777777777777777777777777777777" | send_page "$ENDPOINT" "duplex" "birdyslim" "pocsag=133704A" +echo -e "Test1234567890_1234567890_Testbericht13377777777777777777777777777777777777777777777777777777777777777777" | send_page "$ENDPOINT" "duplex" "birdyslim" "pocsag=133704A" +echo -e "Test1234567890_1234567890_Testbericht13377777777777777777777777777777777777777777777777777777777777777777" | send_page "$ENDPOINT" "duplex" "birdyslim" "pocsag=133704A" +echo -e "Test1234567890_1234567890_Testbericht13377777777777777777777777777777777777777777777777777777777777777777" | send_page "$ENDPOINT" "duplex" "birdyslim" "pocsag=133704A" +echo -e "Test1234567890_1234567890_Testbericht13377777777777777777777777777777777777777777777777777777777777777777" | send_page "$ENDPOINT" "duplex" "birdyslim" "pocsag=133704A" +echo -e "Test1234567890_1234567890_Testbericht13377777777777777777777777777777777777777777777777777777777777777777" | send_page "$ENDPOINT" "duplex" "birdyslim" "pocsag=133704A" +echo -e "Test1234567890_1234567890_Testbericht13377777777777777777777777777777777777777777777777777777777777777777" | send_page "$ENDPOINT" "duplex" "birdyslim" "pocsag=133704A" +echo -e "Test1234567890_1234567890_Testbericht13377777777777777777777777777777777777777777777777777777777777777777" | send_page "$ENDPOINT" "duplex" "birdyslim" "pocsag=133704A" +echo -e "Test1234567890_1234567890_Testbericht13377777777777777777777777777777777777777777777777777777777777777777" | send_page "$ENDPOINT" "duplex" "birdyslim" "pocsag=133704A" +echo -e "Test1234567890_1234567890_Testbericht13377777777777777777777777777777777777777777777777777777777777777777" | send_page "$ENDPOINT" "duplex" "birdyslim" "pocsag=133704A" +echo -e "Test1234567890_1234567890_Testbericht13377777777777777777777777777777777777777777777777777777777777777777" | send_page "$ENDPOINT" "duplex" "birdyslim" "pocsag=133704A" +echo -e "Test1234567890_1234567890_Testbericht13377777777777777777777777777777777777777777777777777777777777777777" | send_page "$ENDPOINT" "duplex" "birdyslim" "pocsag=133704A" +echo -e "Test1234567890_1234567890_Testbericht13377777777777777777777777777777777777777777777777777777777777777777" | send_page "$ENDPOINT" "duplex" "birdyslim" "pocsag=133704A" +echo -e "Test1234567890_1234567890_Testbericht13377777777777777777777777777777777777777777777777777777777777777777" | send_page "$ENDPOINT" "duplex" "birdyslim" "pocsag=133704A" +echo -e "Test1234567890_1234567890_Testbericht13377777777777777777777777777777777777777777777777777777777777777777" | send_page "$ENDPOINT" "duplex" "birdyslim" "pocsag=133704A" +echo -e "Test1234567890_1234567890_Testbericht13377777777777777777777777777777777777777777777777777777777777777777" | send_page "$ENDPOINT" "duplex" "birdyslim" "pocsag=133704A" +echo -e "Test1234567890_1234567890_Testbericht13377777777777777777777777777777777777777777777777777777777777777777" | send_page "$ENDPOINT" "duplex" "birdyslim" "pocsag=133704A" +echo -e "Test1234567890_1234567890_Testbericht13377777777777777777777777777777777777777777777777777777777777777777" | send_page "$ENDPOINT" "duplex" "birdyslim" "pocsag=133704A" +echo -e "Test1234567890_1234567890_Testbericht13377777777777777777777777777777777777777777777777777777777777777777" | send_page "$ENDPOINT" "duplex" "birdyslim" "pocsag=133704A" +echo -e "Test1234567890_1234567890_Testbericht13377777777777777777777777777777777777777777777777777777777777777777" | send_page "$ENDPOINT" "duplex" "birdyslim" "pocsag=133704A" +echo -e "Test1234567890_1234567890_Testbericht13377777777777777777777777777777777777777777777777777777777777777777" | send_page "$ENDPOINT" "duplex" "birdyslim" "pocsag=133704A" +echo -e "Test1234567890_1234567890_Testbericht13377777777777777777777777777777777777777777777777777777777777777777" | send_page "$ENDPOINT" "duplex" "birdyslim" "pocsag=133704A" +echo -e "Test1234567890_1234567890_Testbericht13377777777777777777777777777777777777777777777777777777777777777777" | send_page "$ENDPOINT" "duplex" "birdyslim" "pocsag=133704A" +echo -e "Test1234567890_1234567890_Testbericht13377777777777777777777777777777777777777777777777777777777777777777" | send_page "$ENDPOINT" "duplex" "birdyslim" "pocsag=133704A" +echo -e "Test1234567890_1234567890_Testbericht13377777777777777777777777777777777777777777777777777777777777777777" | send_page "$ENDPOINT" "duplex" "birdyslim" "pocsag=133704A" +echo -e "Test1234567890_1234567890_Testbericht13377777777777777777777777777777777777777777777777777777777777777777" | send_page "$ENDPOINT" "duplex" "birdyslim" "pocsag=133704A" diff --git a/types/MessageManager.js b/types/MessageManager.js index 9a6305a..2b26eb6 100644 --- a/types/MessageManager.js +++ b/types/MessageManager.js @@ -79,13 +79,15 @@ class MessageManager { this.messages[ msgId ]._routerData.response = response this.events.emit('event', 'response', [msgId, response]) if (!!this.messages[ msgId ]._routerData.menu && !!this.messages[ msgId ]._routerData.menu.options) { - + let menuOption = Uint8Array.from(response).reduce((a,b) => a+b,0) + //console.log('response menuOption', response[0], '/', +response[0], Uint8Array.from(response), menuOption) + const menuOptions = this.messages[ msgId ]._routerData.menu.options - console.log(this.messages[ msgId ]._routerData.menu, menuOptions, parseInt(response) - 1, clamp(-1+response, 0, Object.keys(menuOptions).length)) + //console.log(this.messages[ msgId ]._routerData.menu, menuOptions, menuOption - 1, clamp(-1+response, 0, Object.keys(menuOptions).length)) const selectedMenu = menuOptions[ Object.keys(menuOptions)[ - clamp(parseInt(response) - 1, 0, Object.keys(menuOptions).length) + clamp(menuOption - 1, 0, Object.keys(menuOptions).length) ] ] - this.events.emit('event', 'menu', [msgId, response, selectedMenu]) + this.events.emit('event', 'menu', [msgId, menuOption, selectedMenu]) if (!!selectedMenu && !!selectedMenu.url) { axios.get(selectedMenu.url).then( () => false ) }