Spaces:
Paused
Paused
File size: 8,631 Bytes
4c58b75 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | const axios = require('axios');
require('dotenv').config();
const ONESIGNAL_APP_ID = process.env.ONESIGNAL_APP_ID;
const ONESIGNAL_REST_KEY = process.env.ONESIGNAL_REST_KEY;
async function sendWelcomeEmail(email, username) {
if (!ONESIGNAL_APP_ID || !ONESIGNAL_REST_KEY) return;
const svgLogo = `
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 950 300" width="100%" height="100%">
<defs>
<linearGradient id="shield-outer" x1="0%" y1="0%" x2="100%" y2="100%"><stop offset="0%" stop-color="#0F172A" /><stop offset="100%" stop-color="#1E3A8A" /></linearGradient>
<linearGradient id="shield-inner" x1="0%" y1="0%" x2="100%" y2="100%"><stop offset="0%" stop-color="#1E3A8A" /><stop offset="100%" stop-color="#2563EB" /></linearGradient>
<linearGradient id="gold-grad" x1="0%" y1="0%" x2="100%" y2="100%"><stop offset="0%" stop-color="#FDE047" /><stop offset="50%" stop-color="#F59E0B" /><stop offset="100%" stop-color="#D97706" /></linearGradient>
<linearGradient id="gold-bright" x1="0%" y1="0%" x2="0%" y2="100%"><stop offset="0%" stop-color="#FEF08A" /><stop offset="100%" stop-color="#F59E0B" /></linearGradient>
<linearGradient id="red-accent" x1="0%" y1="0%" x2="100%" y2="100%"><stop offset="0%" stop-color="#EF4444" /><stop offset="100%" stop-color="#B91C1C" /></linearGradient>
<linearGradient id="text-silver" x1="0%" y1="0%" x2="0%" y2="100%"><stop offset="0%" stop-color="#FFFFFF" /><stop offset="100%" stop-color="#CBD5E1" /></linearGradient>
<linearGradient id="base-grad" x1="0%" y1="0%" x2="100%" y2="0%"><stop offset="0%" stop-color="#94A3B8" /><stop offset="45%" stop-color="#64748B" /><stop offset="55%" stop-color="#D97706" /><stop offset="100%" stop-color="#F59E0B" /></linearGradient>
<linearGradient id="base-top-grad" x1="0%" y1="0%" x2="100%" y2="0%"><stop offset="0%" stop-color="#CBD5E1" /><stop offset="45%" stop-color="#94A3B8" /><stop offset="55%" stop-color="#FBBF24" /><stop offset="100%" stop-color="#FDE047" /></linearGradient>
<filter id="drop-shadow" x="-20%" y="-20%" width="140%" height="140%"><feDropShadow dx="0" dy="6" stdDeviation="8" flood-color="#000000" flood-opacity="0.5"/></filter>
<filter id="glow-light" x="-20%" y="-20%" width="140%" height="140%"><feGaussianBlur stdDeviation="3" result="blur" /><feComposite in="SourceGraphic" in2="blur" operator="over" /></filter>
</defs>
<g id="PowerShift-Logo" filter="url(#drop-shadow)">
<g id="Icon-Group" transform="translate(40, 30)">
<path id="shield-base" d="M 100 10 L 190 40 L 190 130 C 190 190 140 220 100 240 C 60 220 10 190 10 130 L 10 40 Z" fill="url(#shield-outer)" />
<path id="shield-inset" d="M 100 18 L 182 46 L 182 128 C 182 182 136 210 100 228 C 64 210 18 182 18 128 L 18 46 Z" fill="url(#shield-inner)" />
<g id="foundation"><path d="M 15 190 L 185 190 L 175 180 L 25 180 Z" fill="url(#base-grad)" /><path d="M 25 180 L 175 180 L 175 170 L 25 170 Z" fill="url(#base-top-grad)" /></g>
<g id="government-structure">
<rect x="25" y="110" width="12" height="60" fill="#F1F5F9" /><rect x="50" y="110" width="12" height="60" fill="#F1F5F9" /><rect x="75" y="110" width="12" height="60" fill="#F1F5F9" />
<path d="M 15 110 L 100 110 L 95 100 L 20 100 Z" fill="#E2E8F0" /><path d="M 25 100 L 100 100 L 100 85 L 40 85 Z" fill="#CBD5E1" />
<path d="M 45 85 L 100 85 L 100 70 L 60 70 Z" fill="#94A3B8" /><path d="M 65 70 L 100 70 L 100 50 L 85 50 Z" fill="#F8FAFC" />
<g fill="#FFFFFF" opacity="0.9">
<polygon points="50,35 51.5,38.5 55,38.5 52.5,40.5 53.5,44 50,42 46.5,44 47.5,40.5 45,38.5 48.5,38.5" />
<polygon points="68,25 69.5,28.5 73,28.5 70.5,30.5 71.5,34 68,32 64.5,34 65.5,30.5 63,28.5 66.5,28.5" />
<polygon points="86,18 87.5,21.5 91,21.5 88.5,23.5 89.5,27 86,25 82.5,27 83.5,23.5 81,21.5 84.5,21.5" />
</g>
</g>
<g id="economic-growth" filter="url(#glow-light)">
<path d="M 104 85 L 122 75 L 122 170 L 104 170 Z" fill="url(#gold-grad)" /><path d="M 104 85 L 108 83 L 108 170 L 104 170 Z" fill="url(#gold-bright)" />
<path d="M 130 60 L 148 50 L 148 170 L 130 170 Z" fill="url(#gold-grad)" /><path d="M 130 60 L 134 58 L 134 170 L 130 170 Z" fill="url(#gold-bright)" />
<path d="M 156 35 L 174 25 L 174 170 L 156 170 Z" fill="url(#gold-grad)" /><path d="M 156 35 L 160 33 L 160 170 L 156 170 Z" fill="url(#gold-bright)" />
<path d="M 156 35 L 174 25 L 174 45 L 156 55 Z" fill="url(#red-accent)" />
</g>
<rect x="99" y="50" width="2" height="120" fill="#FEF08A" opacity="0.85" filter="url(#glow-light)"/>
<path d="M 122 110 L 145 110" stroke="#FFFFFF" stroke-width="1.5" opacity="0.4" /><path d="M 148 80 L 168 80" stroke="#FFFFFF" stroke-width="1.5" opacity="0.4" />
<circle cx="145" cy="110" r="2" fill="#FFFFFF" opacity="0.6" /><circle cx="168" cy="80" r="2" fill="#FFFFFF" opacity="0.6" />
</g>
<g id="Typography-Group" transform="translate(310, 25) skewX(-10)">
<g fill="url(#text-silver)">
<path d="M 0 90 L 40 90 L 55 105 L 55 120 L 40 135 L 14 135 L 14 160 L 0 160 Z M 14 104 L 14 121 L 38 121 L 41 118 L 41 107 L 38 104 Z" />
<path d="M 80 110 L 110 110 L 120 120 L 120 150 L 110 160 L 80 160 L 70 150 L 70 120 Z M 84 124 L 106 124 L 106 146 L 84 146 Z" />
<path d="M 130 110 L 144 110 L 154 145 L 164 110 L 178 110 L 188 145 L 198 110 L 212 110 L 195 160 L 181 160 L 171 130 L 161 160 L 147 160 Z" />
<path d="M 225 120 L 235 110 L 270 110 L 270 124 L 239 124 L 239 130 L 265 130 L 265 144 L 239 144 L 239 146 L 270 146 L 270 160 L 235 160 L 225 150 Z" />
<path d="M 290 110 L 304 110 L 304 124 L 320 110 L 325 115 L 325 128 L 315 128 L 304 139 L 304 160 L 290 160 Z" />
</g>
<g fill="url(#gold-grad)">
<path d="M 395 90 L 355 90 L 345 100 L 345 132 L 381 132 L 381 146 L 345 146 L 345 160 L 385 160 L 395 150 L 395 118 L 359 118 L 359 104 L 395 104 Z" />
<path d="M 415 90 L 429 90 L 429 124 L 441 110 L 455 110 L 455 160 L 441 160 L 441 128 L 429 140 L 429 160 L 415 160 Z" />
<path d="M 470 110 L 484 110 L 484 124 L 470 124 Z" />
<path d="M 470 134 L 484 134 L 484 160 L 470 160 Z" />
<path d="M 510 90 L 535 90 L 535 104 L 510 104 L 510 118 L 535 118 L 535 132 L 510 132 L 510 160 L 496 160 L 496 132 L 486 132 L 486 118 L 496 118 L 496 104 L 510 90 Z" />
<path d="M 555 100 L 569 100 L 569 118 L 580 118 L 580 132 L 569 132 L 569 160 L 555 160 L 555 132 L 545 132 L 545 118 L 555 118 Z" />
</g>
</g>
</g>
</svg>`;
const htmlBody = `
<div style="background-color: #000; color: #fff; padding: 20px; font-family: sans-serif; text-align: center;">
${svgLogo}
<h2 style="color: #3b82f6;">Welcome, ${username}!</h2>
<p>Thank you for subscribing to our email marketing. A small gift has been sent to your game email account; you can claim it anytime.</p>
<p>If you wish to avoid missing messages, events, or gift alerts, you can set our email address as a favorite in Gmail.</p>
<p>If you wish to cancel email notifications, you can do so at any time within the game via the Settings button in the Privacy section.</p>
<br>
<p>Thank you for your trust and support.</p>
<p><strong>SkyData Studio | PowerShift</strong></p>
<hr style="border-color: #333; margin: 20px 0;">
<p style="font-size: 12px; color: #888;">
<a href="https://skydata.bond/privacy" style="color: #3b82f6;">Privacy Policy</a> |
<a href="https://skydata.bond/terms" style="color: #3b82f6;">Terms of Service</a>
</p>
</div>
`;
try {
await axios.post('https://onesignal.com/api/v1/notifications', {
app_id: ONESIGNAL_APP_ID,
include_email_tokens: [email],
email_subject: "Welcome to SkyData | PowerShift",
email_body: htmlBody
}, {
headers: {
'Authorization': `Basic ${ONESIGNAL_REST_KEY}`,
'Content-Type': 'application/json'
}
});
console.log(`Welcome email sent to ${email}`);
} catch (err) {
console.error("OneSignal Error:", err.response ? err.response.data : err.message);
}
}
module.exports = { sendWelcomeEmail }; |