7.4 KiB
7.4 KiB
Response Wall Feature Updates
Overview
Updated the Response Wall submission modal to include two new features:
- Postal Code Lookup - Auto-fill representative details by searching postal codes
- Response Verification - Option to send verification email to representatives
Frontend Changes Completed
1. HTML Updates (response-wall.html)
- Added postal code search input field with search button
- Added representative selection dropdown (hidden by default, shows after search)
- Added hidden field for storing representative email
- Added "Send verification request" checkbox option
- Included
api-client.jsscript dependency
2. JavaScript Updates (response-wall.js)
- Added
loadedRepresentativesarray to store search results - Implemented
formatPostalCodeInput()- formats postal code as "A1A 1A1" - Implemented
validatePostalCode()- validates Canadian (Alberta) postal codes - Implemented
handlePostalLookup()- fetches representatives from API - Implemented
displayRepresentativeOptions()- populates dropdown with results - Implemented
handleRepresentativeSelect()- auto-fills form when rep selected - Implemented
determineGovernmentLevel()- maps office type to government level - Updated
handleSubmitResponse()- includes verification flag and rep email - Updated
closeSubmitModal()- resets postal lookup fields
3. CSS Updates (response-wall.css)
- Added
.postal-lookup-containerstyles for search UI - Added
#rep-selectand#rep-select-groupstyles for dropdown - Added checkbox styling improvements
- Added disabled state styling for verification checkbox
Backend Implementation - ✅ COMPLETED
1. API Endpoint Updates - ✅ COMPLETED
Update: POST /api/campaigns/:slug/responses - ✅ COMPLETED
The endpoint now handles new fields:
New Request Fields:
{
// ... existing fields ...
representative_email: String, // Email address of the representative
send_verification: Boolean // Whether to send verification email
}
Implementation Requirements:
- Accept and validate
representative_emailfield - Accept
send_verificationboolean flag - When
send_verification === trueANDrepresentative_emailis present:- Generate a unique verification token
- Store token with the response record
- Send verification email to representative
2. Database Schema Updates - ✅ COMPLETED
responses table additions: ✅ Implemented in scripts/build-nocodb.sh
representative_email- Email field for storing rep emailverification_token- SingleLineText for unique verification tokenverification_sent_at- DateTime for tracking when email was sentverified_at- DateTime for tracking verification timestampverified_by- SingleLineText for tracking who verified
3. Verification Email Template - ✅ COMPLETED
Created email templates in app/templates/email/:
Subject: "Verification Request: Response Submission on BNKops Influence"
Body:
Dear [Representative Name],
A constituent has submitted a response they received from you on the BNKops Influence platform.
Campaign: [Campaign Name]
Response Type: [Email/Letter/etc.]
Submitted: [Date]
To verify this response is authentic, please click the link below:
[Verification Link]
If you did not send this response, please click here to report it:
[Report Link]
This helps maintain transparency and accountability in constituent communications.
Best regards,
BNKops Influence Team
4. Verification Endpoints (New) - ✅ COMPLETED
GET /api/responses/:id/verify/:token - ✅ COMPLETED
Implemented in app/controllers/responses.js:
- Verifies response using unique token
- Updates
verified_attimestamp - Marks response as verified (
is_verified: true) - Auto-approves response (
status: 'approved') - Returns styled HTML success page
GET /api/responses/:id/report/:token - ✅ COMPLETED
Implemented in app/controllers/responses.js:
- Marks response as disputed by representative
- Updates response status to 'rejected'
- Sets
is_verified: false - Hides from public view (rejected status)
- Returns styled HTML confirmation page
5. Email Service Integration - ✅ COMPLETED
Updated email service with verification support:
File: app/services/email.js
async function sendVerificationEmail(responseId, representativeEmail, representativeName, verificationToken) {
const verificationUrl = `${process.env.BASE_URL}/api/responses/${responseId}/verify/${verificationToken}`;
const reportUrl = `${process.env.BASE_URL}/api/responses/${responseId}/report/${verificationToken}`;
// Send email using your email service
// Include verification and report links
}
6. Environment Variables - ✅ COMPLETED
Added to example.env:
APP_NAME="BNKops Influence"
BASE_URL=http://localhost:3333
Note: Update your .env file with these values for production deployment.
User Flow
Submitting with Verification
- User clicks "Share a Response"
- User enters postal code and clicks search
- System fetches representatives from Represent API
- User selects their representative from dropdown
- Form auto-fills: name, title, level, email (hidden)
- User completes response details
- User checks "Send verification request"
- User submits form
- Backend: Response saved as pending/unverified
- Backend: Verification email sent to representative
- User sees success message
Representative Verification
- Representative receives email
- Clicks verification link
- Redirects to verification endpoint
- Response marked as verified
- Response becomes visible with "Verified" badge
Testing Checklist
Frontend Testing
- Postal code search works with valid Alberta codes
- Validation rejects non-Alberta codes
- Representative dropdown populates correctly
- Selecting a rep auto-fills form fields
- Verification checkbox is disabled when no email
- Verification checkbox is enabled when rep has email
- Form submits successfully with verification flag
- Manual entry still works without postal lookup
- Modal resets properly when closed
Backend Testing
- Backend receives verification parameters correctly
- Verification token is generated and stored
- Verification email is sent when opted in
- Email contains correct verification and report URLs
- Verification endpoint validates token correctly
- Verification endpoint updates database correctly
- Report endpoint marks response as disputed
- Styled HTML pages display correctly on verify/report
- Security: Invalid tokens are rejected
- Security: Already verified responses show appropriate message
Security Considerations
- Token Security: Use cryptographically secure random tokens
- Token Expiry: Verification tokens should expire (e.g., 30 days)
- Rate Limiting: Limit verification emails per IP/session
- Email Validation: Validate representative email format
- XSS Prevention: Sanitize all form inputs on backend
- CSRF Protection: Ensure CSRF tokens on form submission
Future Enhancements
- Add notification when representative verifies
- Show verification status prominently on response cards
- Add statistics: "X% of responses verified"
- Allow representatives to add comments during verification
- Add representative dashboard to manage verifications
- Support for multiple verification methods (SMS, etc.)