Skip to content

Commit 23ce7a7

Browse files
authored
Merge pull request #1341 from ainblockchain/bugfix/platfowner/bugfix
Update echo-bot code
2 parents 3197aec + e1d87aa commit 23ce7a7

File tree

4 files changed

+15
-13
lines changed

4 files changed

+15
-13
lines changed

tools/chatbot/sendCreateAppAndConfigTx.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ function buildChatbotConfigTxBody(timestamp) {
2727
op_list: [
2828
{
2929
type: "SET_OWNER",
30-
ref: `/apps/${config.appName}/common/messages`,
30+
ref: `/apps/${config.appName}/messages`,
3131
value: {
3232
".owner": {
3333
owners: {
3434
"*": {
35-
branch_owner: true,
35+
branch_owner: false,
3636
write_function: true,
3737
write_owner: true,
3838
write_rule: true
@@ -43,7 +43,7 @@ function buildChatbotConfigTxBody(timestamp) {
4343
},
4444
{
4545
type: "SET_RULE",
46-
ref: `/apps/${config.appName}/common/messages/$key`,
46+
ref: `/apps/${config.appName}/messages/$addr/$key`,
4747
value: {
4848
".rule": {
4949
"write": true
@@ -52,13 +52,13 @@ function buildChatbotConfigTxBody(timestamp) {
5252
},
5353
{
5454
type: "SET_FUNCTION",
55-
ref: `/apps/${config.appName}/common/messages/$key/user`,
55+
ref: `/apps/${config.appName}/messages/$addr/$key/user`,
5656
value: {
5757
".function": {
58-
"liayoo-ainjs": {
58+
"echo-bot": {
5959
function_type: "REST",
6060
function_url: "http://localhost:3000/trigger",
61-
function_id: "liayoo-ainjs"
61+
function_id: "echo-bot"
6262
}
6363
}
6464
}

tools/chatbot/sendMessageTx.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ const path = require('path');
44
const { signAndSendTx, confirmTransaction } = require('../util');
55
let config = {};
66

7-
function buildMessageTxBody(timestamp, message) {
7+
function buildMessageTxBody(address, timestamp, message) {
88
return {
99
operation: {
1010
type: 'SET_VALUE',
11-
ref: `/apps/${config.appName}/common/messages/${timestamp}/user`,
11+
ref: `/apps/${config.appName}/messages/${address}/${timestamp}/user`,
1212
value: message,
1313
},
1414
gas_price: 500,
@@ -17,11 +17,11 @@ function buildMessageTxBody(timestamp, message) {
1717
};
1818
}
1919

20-
async function sendTransaction(message) {
20+
async function sendTransaction(config, message) {
2121
console.log('\n*** sendTransaction():');
2222
const timestamp = Date.now();
2323

24-
const txBody = buildMessageTxBody(timestamp, message);
24+
const txBody = buildMessageTxBody(config.userAddr, timestamp, message);
2525
console.log(`txBody: ${JSON.stringify(txBody, null, 2)}`);
2626

2727
const txInfo = await signAndSendTx(config.endpointUrl, txBody, config.serviceOwnerPrivateKey, config.chainId);
@@ -42,7 +42,7 @@ async function processArguments() {
4242
message = process.argv[3];
4343
}
4444
config = require(path.resolve(__dirname, process.argv[2]));
45-
await sendTransaction(message);
45+
await sendTransaction(config, message);
4646
}
4747

4848
function usage() {

tools/simple-chatbot-server/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ app.post('/trigger', async (req, res) => {
4242
const ref = _.get(tx, 'tx_body.operation.ref');
4343
const parsedRef = CommonUtil.parsePath(ref);
4444
const userVal = _.get(tx, 'tx_body.operation.value');
45-
if (parsedRef.length !== 6 || parsedRef[0] !== 'apps' || parsedRef[1] !== APP_NAME ||
46-
parsedRef[3] !== 'messages' || parsedRef[5] !== 'user') {
45+
if (parsedRef.length !== 6 || parsedRef[0] !== 'apps' ||
46+
parsedRef[2] !== 'messages' || parsedRef[5] !== 'user') {
4747
console.log(`Not supported path pattern: ${ref}`);
4848
return;
4949
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
nohup node ./index.js >console_logs.txt 2>error_logs.txt &
2+

0 commit comments

Comments
 (0)