Skip to content

Commit

Permalink
Merge pull request #1341 from ainblockchain/bugfix/platfowner/bugfix
Browse files Browse the repository at this point in the history
Update echo-bot code
  • Loading branch information
platfowner authored Dec 27, 2024
2 parents 3197aec + e1d87aa commit 23ce7a7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
12 changes: 6 additions & 6 deletions tools/chatbot/sendCreateAppAndConfigTx.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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"
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions tools/chatbot/sendMessageTx.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand All @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions tools/simple-chatbot-server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions tools/simple-chatbot-server/start_echo_bot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
nohup node ./index.js >console_logs.txt 2>error_logs.txt &

0 comments on commit 23ce7a7

Please sign in to comment.