Verify User and Send Notification Using v2 Bot
Description:
This task involves verifying a user on the v2 bot before sending a notification and then logging the process and results in the database. The steps include checking the user's existence, adding the user if they are not already recognized, handling cases where a contact_key is not immediately available, sending the notification, and storing the notification details with its status in the database.
Acceptance Criteria:
-
Verify User on the v2 Bot:
-
Call the
/contact/{pubkey}endpoint to check if the user exists.- Expected Response:
{ version: number; my_idx: number; pubkey: string; lsp: string; scid: number; contact_key?: string; } - Condition:
- If
contact_keyis empty, the bot does not recognize the user.
- If
- Expected Response:
-
Add the user to the bot's known contacts by calling the
/add_contactendpoint.- Expected Request Body
{ contact_info: string; alias?: string; }
- Expected Request Body
-
Re-check the
/contact/{pubkey}endpoint to verify thecontact_keyis now populated. -
Handling Missing
contact_key:- If
contact_keyis still empty, store the notification details in the database with a status ofWAITING_KEY_EXCHANGE.
- If
-
-
Send Notification:
-
Use the
/sendendpoint to send the notification.-
Request Body for Text Messages:
{ dest: string; // User's pubkey amt_msat: 0; // Set to 0 for text messages content: string; // Notification content is_tribe: false; // Set to false for direct messages wait: true; // Set to true for synchronous behavior } -
Expected Response:
{ status: SendOnionStatus; // "COMPLETE", "PENDING", or "FAILED" tag: string; preimage?: string; payment_hash?: string; message?: string; // Error message if status == "FAILED" }
-
-
Log the notification details and the response in the database, including the status (
COMPLETE,PENDING, orFAILED).
-
-
Database Integration:
- Ensure the database table
notificationsis used for tracking. Fields should include:event(e.g.,bounty_assigned)pubkeycontentretriesstatusuuidcreated_at
- Ensure the database table
This ticket depends on this ticket
@humansinstitute Please assign me?
@humansinstitute @tobi-bams assign me?
@humansinstitute please assign me