Skip to content

Commit

Permalink
feat: improve message formatting and enhance user instructions in wal…
Browse files Browse the repository at this point in the history
…let commands
  • Loading branch information
Salasifaoui committed Nov 14, 2024
1 parent b53713d commit 0e896d7
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 33 deletions.
4 changes: 3 additions & 1 deletion src/bots/@base/OpenAIAssistantBot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ export abstract class OpenAIAssistantBot extends BaseBot {
for (const reply of messages.data.reverse()) {
console.log('AI REPLU::', JSON.stringify(reply, null, 2))
console.log(`${reply.role} > ${reply.content[0].text.value}`);
onReply(this.markdownConverter.makeHtml(reply.content[0].text.value));
onReply(
reply.content[0].text.value
);
break;
}
} else if (run.status === 'requires_action' && run.required_action) {
Expand Down
8 changes: 5 additions & 3 deletions src/bots/ae_wallet/WalletCommands/ConnectWalletCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ class ConnectWalletError extends UserFacingError {
constructor(message: string) {
super(
message +
"<br /><br />To connect your wallet, please use this format: <b>/connect “address”</b>.<br />For example: /connect ak_xyz",
"\n\nTo connect your wallet, please use this format: /connect “address”. For example: /connect ak_xyz",
);


Object.setPrototypeOf(this, UserFacingError.prototype);
}
Expand Down Expand Up @@ -92,9 +93,10 @@ export class ConnectWalletCommand extends BotCommand {
rawTx,
`ae-wallet-bot/verified-wallet/${id}`,
);

return `
<p>🔗 Sure! To connect the wallet, please sign the transaction link below to connect your Superhero Wallet with me. 🦸‍♂️</p>
<p><a href="${signTransactionUrl}" target="_blank">Sign Transaction</a></p>
🔗 Sure! To connect the wallet, please sign the transaction link below to connect your Superhero Wallet with me. 🦸‍♂️
[Sign Transaction](${signTransactionUrl})
`;
}
}
4 changes: 2 additions & 2 deletions src/bots/ae_wallet/WalletCommands/DisconnectWalletCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ export class DisconnectWalletCommand extends BotCommand {
`ae-wallet-bot/remove-verified-wallet/${id}`,
);
return `
<p>🔗 Sure! To remove the previous connection, please sign the transaction using the link below:</p>
<p><a href="${signTransactionUrl}" target="_blank">Remove Connection</a></p>
🔗 Sure! To remove the previous connection, please sign the transaction using the link below:
[Remove Connection](${signTransactionUrl})
`;
}
}
17 changes: 6 additions & 11 deletions src/bots/ae_wallet/WalletCommands/TransferTokenCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,9 @@ export class TransferTokenCommand extends BotCommand {
? `, wallet address: ${recipientAddress}`
: "";

// Construct confirmation message
// Construct confirmation message with named anchor text
return `
<p>👍 Sure thing! Please confirm the transaction through the link provided,
and I will immediately initiate the transfer to ${recipient}${recipientInfo}:</p>
<p><a href="${signTransactionUrl}" target="_blank">Confirm Transaction</a> 🔗</p>
`;

return `👍 Sure thing! Please confirm the transaction through the link provided, and I will immediately initiate the transfer to ${recipient}${recipientInfo}:
[Confirm Transaction](${signTransactionUrl}) 🔗`;
}

private async handleTokenTransfer(
Expand Down Expand Up @@ -314,10 +310,9 @@ export class TransferTokenCommand extends BotCommand {
: "";

// Construct confirmation message
const confirmationMessage = `
<p>👍 Sure thing! Please confirm the transaction through the link provided,
and I will immediately initiate the transfer to ${recipient}${recipientInfo}:</p>
<p><a href="${signTransactionUrl}" target="_blank">Confirm Transaction</a> 🔗</p>`;
const confirmationMessage = `👍 Sure thing! Please confirm the transaction through the link provided,
and I will immediately initiate the transfer to ${recipient}${recipientInfo}:
[Confirm Transaction](${signTransactionUrl}) 🔗`;

return confirmationMessage;
}
Expand Down
14 changes: 5 additions & 9 deletions src/bots/ae_wallet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,11 @@ export class AeWalletBot extends OpenAIAssistantBot {
metaData: IRoomMetadata,
): Promise<string | null> {
if (metaData.isDirect) {
return `<p>Hi there! 👋 Welcome to the Wallet Bot! I'm your trusted DeFi companion, here to simplify your crypto experience! With my superpowers, I can securely transfer your tokens, check your balance, and more! </p>
<p>But before we dive in, let's get you set up:</p>
<ol>
<li>First, download the Superhero Wallet: <a href="https://wallet.superhero.com" target="_blank" style="color: #1D9BF0; text-decoration: none;">Superhero Wallet</a> 📥</li>
<li>After you have downloaded the Wallet and created an account, connect your Superhero Wallet to me.</li>
<li>Type: <code>/connect "your wallet address"</code><br>For example: <code>/connect ak_xyz</code></li>
</ol>`;
return `Hi there! 👋 Welcome to the Wallet Bot! I'm your trusted DeFi companion, here to simplify your crypto experience! With my superpowers, I can securely transfer your tokens, check your balance, and more!
\n\nBut before we dive in, let's get you set up:
\n\n1. First, download the Superhero Wallet: [Superhero Wallet](https://wallet.superhero.com) 📥
\n2. After you have downloaded the Wallet and created an account, connect your Superhero Wallet to me.
\n3. Type: \`/connect "your wallet address"\` \nFor example: \`/connect ak_xyz\``;
}
return null;
}
Expand Down
16 changes: 9 additions & 7 deletions src/utils/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ export class MultipleTokensFoundError extends UserFacingError {
}[],
token: string,
) {
super(`<p>I see you own multiple ${token} tokens in your Superhero Wallet. Please reply with the number of the option you want to transfer from:</p>
<ol>
${tokenListInaction
.map(
({ contractId, symbol }) => `<li>${symbol} ${contractId}</li>`,
)
.join("")}</ol>`);
super(
`I see you own multiple ${token} tokens in your Superhero Wallet. Please reply with the number of the option you want to transfer from:
${tokenListInaction
.map(
({ contractId, symbol }) => `${symbol} ${contractId}`,
)
.join("")}`,
);


Object.setPrototypeOf(this, NoTokenFoundError.prototype);
}
Expand Down

0 comments on commit 0e896d7

Please sign in to comment.