From e25f8779058a5d30389edc2fd0ba5a18ca39ba90 Mon Sep 17 00:00:00 2001 From: platfowner Date: Thu, 26 Dec 2024 16:42:12 +0900 Subject: [PATCH 1/2] Update echo-bot message path --- tools/chatbot/sendCreateAppAndConfigTx.js | 12 ++++++------ tools/chatbot/sendMessageTx.js | 10 +++++----- tools/simple-chatbot-server/index.js | 4 ++-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/tools/chatbot/sendCreateAppAndConfigTx.js b/tools/chatbot/sendCreateAppAndConfigTx.js index 20c297003..687acde73 100644 --- a/tools/chatbot/sendCreateAppAndConfigTx.js +++ b/tools/chatbot/sendCreateAppAndConfigTx.js @@ -27,12 +27,12 @@ function buildChatbotConfigTxBody(timestamp) { op_list: [ { type: "SET_OWNER", - ref: `/apps/${config.appName}/common/messages`, + ref: `/apps/${config.appName}/messages`, value: { ".owner": { owners: { "*": { - branch_owner: true, + branch_owner: false, write_function: true, write_owner: true, write_rule: true @@ -43,7 +43,7 @@ function buildChatbotConfigTxBody(timestamp) { }, { type: "SET_RULE", - ref: `/apps/${config.appName}/common/messages/$key`, + ref: `/apps/${config.appName}/messages/$addr/$key`, value: { ".rule": { "write": true @@ -52,13 +52,13 @@ function buildChatbotConfigTxBody(timestamp) { }, { type: "SET_FUNCTION", - ref: `/apps/${config.appName}/common/messages/$key/user`, + ref: `/apps/${config.appName}/messages/$addr/$key/user`, value: { ".function": { - "liayoo-ainjs": { + "echo-bot": { function_type: "REST", function_url: "http://localhost:3000/trigger", - function_id: "liayoo-ainjs" + function_id: "echo-bot" } } } diff --git a/tools/chatbot/sendMessageTx.js b/tools/chatbot/sendMessageTx.js index a5059e5d1..49373f0ec 100644 --- a/tools/chatbot/sendMessageTx.js +++ b/tools/chatbot/sendMessageTx.js @@ -4,11 +4,11 @@ const path = require('path'); const { signAndSendTx, confirmTransaction } = require('../util'); let config = {}; -function buildMessageTxBody(timestamp, message) { +function buildMessageTxBody(address, timestamp, message) { return { operation: { type: 'SET_VALUE', - ref: `/apps/${config.appName}/common/messages/${timestamp}/user`, + ref: `/apps/${config.appName}/messages/${address}/${timestamp}/user`, value: message, }, gas_price: 500, @@ -17,11 +17,11 @@ function buildMessageTxBody(timestamp, message) { }; } -async function sendTransaction(message) { +async function sendTransaction(config, message) { console.log('\n*** sendTransaction():'); const timestamp = Date.now(); - const txBody = buildMessageTxBody(timestamp, message); + const txBody = buildMessageTxBody(config.userAddr, timestamp, message); console.log(`txBody: ${JSON.stringify(txBody, null, 2)}`); const txInfo = await signAndSendTx(config.endpointUrl, txBody, config.serviceOwnerPrivateKey, config.chainId); @@ -42,7 +42,7 @@ async function processArguments() { message = process.argv[3]; } config = require(path.resolve(__dirname, process.argv[2])); - await sendTransaction(message); + await sendTransaction(config, message); } function usage() { diff --git a/tools/simple-chatbot-server/index.js b/tools/simple-chatbot-server/index.js index c18749277..168a19d1a 100644 --- a/tools/simple-chatbot-server/index.js +++ b/tools/simple-chatbot-server/index.js @@ -42,8 +42,8 @@ app.post('/trigger', async (req, res) => { const ref = _.get(tx, 'tx_body.operation.ref'); const parsedRef = CommonUtil.parsePath(ref); const userVal = _.get(tx, 'tx_body.operation.value'); - if (parsedRef.length !== 6 || parsedRef[0] !== 'apps' || parsedRef[1] !== APP_NAME || - parsedRef[3] !== 'messages' || parsedRef[5] !== 'user') { + if (parsedRef.length !== 6 || parsedRef[0] !== 'apps' || + parsedRef[2] !== 'messages' || parsedRef[5] !== 'user') { console.log(`Not supported path pattern: ${ref}`); return; } From e1d87aaaea88acc78ac53afc981ee6cd9f9fe8a8 Mon Sep 17 00:00:00 2001 From: platfowner Date: Thu, 26 Dec 2024 16:42:36 +0900 Subject: [PATCH 2/2] Add start_echo_bot.sh --- tools/simple-chatbot-server/start_echo_bot.sh | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 tools/simple-chatbot-server/start_echo_bot.sh diff --git a/tools/simple-chatbot-server/start_echo_bot.sh b/tools/simple-chatbot-server/start_echo_bot.sh new file mode 100644 index 000000000..bcf5fb41b --- /dev/null +++ b/tools/simple-chatbot-server/start_echo_bot.sh @@ -0,0 +1,2 @@ +nohup node ./index.js >console_logs.txt 2>error_logs.txt & +