Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update echo-bot code #1341

Merged
merged 2 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 &

Loading