683 lines
24 KiB
HTML
683 lines
24 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="fa" dir="rtl">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<title>راهنمای جامع ساخت بات بله با C# | پیادهسازی سیستم نوتیفیکیشن</title>
|
||
<style>
|
||
@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@300;400;500;600;700;800&display=swap');
|
||
:root {
|
||
--primary: #1a365d;
|
||
--primary-light: #2c5282;
|
||
--accent: #c9a961;
|
||
--accent-dark: #a8893f;
|
||
--bg: #faf9f6;
|
||
--card-bg: #ffffff;
|
||
--text: #1a202c;
|
||
--text-muted: #4a5568;
|
||
--border: #e2e8f0;
|
||
--success: #38a169;
|
||
--danger: #e53e3e;
|
||
--warning: #dd6b20;
|
||
--shadow: 0 4px 6px rgba(0,0,0,0.05), 0 10px 30px rgba(26,54,93,0.08);
|
||
}
|
||
* { box-sizing: border-box; margin: 0; padding: 0; }
|
||
body {
|
||
font-family: 'Vazirmatn', Tahoma, sans-serif;
|
||
background: var(--bg);
|
||
color: var(--text);
|
||
line-height: 1.9;
|
||
font-size: 15px;
|
||
padding: 30px 15px;
|
||
}
|
||
.document-container {
|
||
max-width: 950px;
|
||
margin: 0 auto;
|
||
background: var(--card-bg);
|
||
box-shadow: var(--shadow);
|
||
border-radius: 12px;
|
||
overflow: hidden;
|
||
}
|
||
.document-header {
|
||
background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
|
||
color: white;
|
||
padding: 50px 40px 40px;
|
||
position: relative;
|
||
border-bottom: 4px solid var(--accent);
|
||
}
|
||
.document-header::before {
|
||
content: '';
|
||
position: absolute;
|
||
top: 0; right: 0;
|
||
width: 200px; height: 200px;
|
||
background: radial-gradient(circle, rgba(201,169,97,0.15) 0%, transparent 70%);
|
||
border-radius: 50%;
|
||
transform: translate(50%, -50%);
|
||
}
|
||
.header-top {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
margin-bottom: 30px;
|
||
position: relative;
|
||
z-index: 1;
|
||
}
|
||
.company-badge {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 12px;
|
||
}
|
||
.company-logo {
|
||
width: 60px; height: 60px;
|
||
background: var(--accent);
|
||
border-radius: 12px;
|
||
box-shadow: 0 4px 12px rgba(0,0,0,0.2);
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
font-weight: 800;
|
||
color: white;
|
||
font-size: 14px;
|
||
}
|
||
.doc-meta {
|
||
text-align: left;
|
||
font-size: 12px;
|
||
opacity: 0.9;
|
||
}
|
||
.doc-meta div { margin-bottom: 3px; }
|
||
.document-title {
|
||
text-align: center;
|
||
position: relative;
|
||
z-index: 1;
|
||
padding: 20px 0;
|
||
}
|
||
.document-title .label {
|
||
display: inline-block;
|
||
background: rgba(201,169,97,0.2);
|
||
color: var(--accent);
|
||
padding: 4px 16px;
|
||
border-radius: 20px;
|
||
font-size: 12px;
|
||
font-weight: 600;
|
||
margin-bottom: 15px;
|
||
border: 1px solid rgba(201,169,97,0.4);
|
||
}
|
||
.document-title h1 {
|
||
font-size: 28px;
|
||
font-weight: 800;
|
||
margin-bottom: 10px;
|
||
letter-spacing: -0.5px;
|
||
}
|
||
.document-title h2 {
|
||
font-size: 16px;
|
||
font-weight: 400;
|
||
opacity: 0.9;
|
||
}
|
||
.document-body {
|
||
padding: 40px;
|
||
}
|
||
.intro-text {
|
||
background: linear-gradient(to left, #f7fafc, #edf2f7);
|
||
border-right: 4px solid var(--accent);
|
||
padding: 20px 25px;
|
||
border-radius: 8px;
|
||
margin-bottom: 35px;
|
||
font-size: 14px;
|
||
color: var(--text-muted);
|
||
}
|
||
.section {
|
||
margin-bottom: 40px;
|
||
page-break-inside: avoid;
|
||
}
|
||
.section-header {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 15px;
|
||
padding-bottom: 12px;
|
||
border-bottom: 2px solid var(--border);
|
||
margin-bottom: 20px;
|
||
}
|
||
.section-number {
|
||
width: 50px; height: 50px;
|
||
background: linear-gradient(135deg, var(--primary), var(--primary-light));
|
||
color: white;
|
||
border-radius: 12px;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
font-weight: 800;
|
||
font-size: 20px;
|
||
flex-shrink: 0;
|
||
box-shadow: 0 4px 10px rgba(26,54,93,0.2);
|
||
}
|
||
.section-title { flex: 1; }
|
||
.section-title h3 {
|
||
font-size: 19px;
|
||
font-weight: 700;
|
||
color: var(--primary);
|
||
margin-bottom: 2px;
|
||
}
|
||
.section-title .subtitle {
|
||
font-size: 12px;
|
||
color: var(--text-muted);
|
||
}
|
||
.section-content {
|
||
padding-right: 10px;
|
||
}
|
||
.section-content p {
|
||
margin-bottom: 12px;
|
||
text-align: justify;
|
||
text-indent: 20px;
|
||
}
|
||
.section-content p.no-indent { text-indent: 0; }
|
||
.highlight-box {
|
||
background: linear-gradient(to left, #fffaf0, #fef5e7);
|
||
border: 1px solid #f6e05e;
|
||
border-right: 4px solid var(--accent);
|
||
padding: 18px 22px;
|
||
border-radius: 8px;
|
||
margin: 20px 0;
|
||
font-size: 14px;
|
||
}
|
||
.highlight-box strong { color: var(--accent-dark); }
|
||
.info-box {
|
||
background: linear-gradient(to left, #ebf8ff, #e6f6ff);
|
||
border: 1px solid #90cdf4;
|
||
border-right: 4px solid var(--primary-light);
|
||
padding: 18px 22px;
|
||
border-radius: 8px;
|
||
margin: 20px 0;
|
||
font-size: 14px;
|
||
}
|
||
.success-box {
|
||
background: linear-gradient(to left, #f0fff4, #e6fffa);
|
||
border: 1px solid #9ae6b4;
|
||
border-right: 4px solid var(--success);
|
||
padding: 18px 22px;
|
||
border-radius: 8px;
|
||
margin: 20px 0;
|
||
font-size: 14px;
|
||
}
|
||
.warning-box {
|
||
background: linear-gradient(to left, #fffaf0, #fef5e7);
|
||
border: 1px solid #fbd38d;
|
||
border-right: 4px solid var(--warning);
|
||
padding: 18px 22px;
|
||
border-radius: 8px;
|
||
margin: 20px 0;
|
||
font-size: 14px;
|
||
}
|
||
.styled-table {
|
||
width: 100%;
|
||
border-collapse: collapse;
|
||
margin: 20px 0;
|
||
background: white;
|
||
border-radius: 8px;
|
||
overflow: hidden;
|
||
box-shadow: 0 2px 8px rgba(0,0,0,0.05);
|
||
}
|
||
.styled-table thead {
|
||
background: linear-gradient(135deg, var(--primary), var(--primary-light));
|
||
color: white;
|
||
}
|
||
.styled-table th {
|
||
padding: 14px 16px;
|
||
text-align: right;
|
||
font-weight: 600;
|
||
font-size: 13px;
|
||
}
|
||
.styled-table td {
|
||
padding: 13px 16px;
|
||
border-bottom: 1px solid var(--border);
|
||
font-size: 13px;
|
||
}
|
||
.styled-table tbody tr:last-child td { border-bottom: none; }
|
||
.styled-table tbody tr:nth-child(even) { background: #f8fafc; }
|
||
.styled-table .highlight-row {
|
||
background: #fffaf0 !important;
|
||
font-weight: 600;
|
||
}
|
||
.code-block {
|
||
background: #1a202c;
|
||
color: #e2e8f0;
|
||
padding: 20px;
|
||
border-radius: 8px;
|
||
font-family: 'Consolas', 'Monaco', monospace;
|
||
font-size: 13px;
|
||
direction: ltr;
|
||
text-align: left;
|
||
overflow-x: auto;
|
||
margin: 20px 0;
|
||
border-right: 4px solid var(--accent);
|
||
}
|
||
.code-block .keyword { color: #569cd6; }
|
||
.code-block .string { color: #ce9178; }
|
||
.code-block .comment { color: #6a9955; }
|
||
.code-block .type { color: #4ec9b0; }
|
||
.comparison-grid {
|
||
display: grid;
|
||
grid-template-columns: 1fr 1fr;
|
||
gap: 20px;
|
||
margin: 25px 0;
|
||
}
|
||
.comparison-card {
|
||
background: #f8fafc;
|
||
border: 2px solid var(--border);
|
||
border-radius: 10px;
|
||
padding: 20px;
|
||
position: relative;
|
||
}
|
||
.comparison-card.recommended {
|
||
border-color: var(--success);
|
||
background: linear-gradient(to left, #f0fff4, #e6fffa);
|
||
}
|
||
.comparison-card .card-badge {
|
||
position: absolute;
|
||
top: -10px;
|
||
right: 20px;
|
||
background: var(--success);
|
||
color: white;
|
||
padding: 3px 12px;
|
||
border-radius: 15px;
|
||
font-size: 11px;
|
||
font-weight: 600;
|
||
}
|
||
.comparison-card h4 {
|
||
font-size: 16px;
|
||
font-weight: 700;
|
||
color: var(--primary);
|
||
margin-bottom: 15px;
|
||
padding-bottom: 10px;
|
||
border-bottom: 2px solid var(--border);
|
||
}
|
||
.comparison-card.recommended h4 { border-bottom-color: var(--success); }
|
||
.comparison-card ul { list-style: none; padding: 0; }
|
||
.comparison-card ul li {
|
||
padding: 8px 0;
|
||
border-bottom: 1px solid var(--border);
|
||
font-size: 13px;
|
||
display: flex;
|
||
justify-content: space-between;
|
||
}
|
||
.comparison-card ul li:last-child { border-bottom: none; }
|
||
.comparison-card ul li .value { font-weight: 600; color: var(--primary); }
|
||
.stats-grid {
|
||
display: grid;
|
||
grid-template-columns: repeat(3, 1fr);
|
||
gap: 15px;
|
||
margin: 25px 0;
|
||
}
|
||
.stat-card {
|
||
background: linear-gradient(135deg, var(--primary), var(--primary-light));
|
||
color: white;
|
||
padding: 20px;
|
||
border-radius: 10px;
|
||
text-align: center;
|
||
box-shadow: 0 4px 12px rgba(26,54,93,0.2);
|
||
}
|
||
.stat-card .stat-value {
|
||
font-size: 24px;
|
||
font-weight: 800;
|
||
margin-bottom: 5px;
|
||
color: var(--accent);
|
||
line-height: 1.3;
|
||
}
|
||
.stat-card .stat-label { font-size: 12px; opacity: 0.9; }
|
||
.conclusion-box {
|
||
background: linear-gradient(135deg, var(--primary), var(--primary-light));
|
||
color: white;
|
||
padding: 30px;
|
||
border-radius: 12px;
|
||
margin: 30px 0;
|
||
text-align: center;
|
||
box-shadow: 0 8px 20px rgba(26,54,93,0.3);
|
||
}
|
||
.conclusion-box h3 {
|
||
font-size: 22px;
|
||
font-weight: 800;
|
||
margin-bottom: 15px;
|
||
color: var(--accent);
|
||
}
|
||
.conclusion-box p {
|
||
font-size: 14px;
|
||
line-height: 1.8;
|
||
text-indent: 0 !important;
|
||
margin-bottom: 15px;
|
||
}
|
||
.conclusion-box .highlight {
|
||
background: rgba(201,169,97,0.2);
|
||
padding: 15px 20px;
|
||
border-radius: 8px;
|
||
margin-top: 20px;
|
||
border: 1px solid rgba(201,169,97,0.4);
|
||
}
|
||
.document-footer {
|
||
background: var(--primary);
|
||
color: white;
|
||
padding: 25px 40px;
|
||
text-align: center;
|
||
font-size: 12px;
|
||
margin-top: 40px;
|
||
}
|
||
.document-footer .footer-brand {
|
||
font-weight: 700;
|
||
color: var(--accent);
|
||
margin-bottom: 5px;
|
||
font-size: 14px;
|
||
}
|
||
.footer-divider {
|
||
width: 60px;
|
||
height: 2px;
|
||
background: var(--accent);
|
||
margin: 10px auto;
|
||
}
|
||
.page-info {
|
||
text-align: center;
|
||
padding: 15px;
|
||
font-size: 11px;
|
||
color: var(--text-muted);
|
||
border-top: 1px solid var(--border);
|
||
margin-top: 30px;
|
||
}
|
||
@media print {
|
||
body { background: white; padding: 0; }
|
||
.document-container { box-shadow: none; border-radius: 0; }
|
||
.section { page-break-inside: avoid; }
|
||
}
|
||
@media (max-width: 768px) {
|
||
.document-body { padding: 25px 20px; }
|
||
.document-header { padding: 30px 20px; }
|
||
.comparison-grid { grid-template-columns: 1fr; }
|
||
.stats-grid { grid-template-columns: 1fr; }
|
||
.header-top { flex-direction: column; gap: 15px; }
|
||
.doc-meta { text-align: center; }
|
||
}
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<div class="document-container">
|
||
<header class="document-header">
|
||
<div class="header-top">
|
||
<div class="company-badge">
|
||
<div class="company-logo">RPK</div>
|
||
</div>
|
||
<div class="doc-meta">
|
||
<div>شماره مستند: TECH-1405-002</div>
|
||
<div>نسخه: ۱.۰</div>
|
||
<div>تاریخ تهیه: آبان ۱۴۰۵</div>
|
||
<div>طبقهبندی: داخلی / فنی</div>
|
||
</div>
|
||
</div>
|
||
<div class="document-title">
|
||
<span class="label">TECHNICAL GUIDE</span>
|
||
<h1>راهنمای جامع ساخت بات بله با C#</h1>
|
||
<h2>پیادهسازی گامبهگام سیستم ارسال نوتیفیکیشن به کاربران</h2>
|
||
</div>
|
||
</header>
|
||
<div class="document-body">
|
||
<div class="intro-text">
|
||
<strong>مدیر انتشار و تیم توسعه محترم،</strong><br>
|
||
این مستند فنی، راهنمای کامل و گامبهگام طراحی و پیادهسازی یک سرویس نوتیفیکیشن مبتنی بر پیامرسان بله با استفاده از زبان C# و فریمورک .NET 8 را ارائه میدهد. هدف، ایجاد یک زیرساخت پایدار، مقیاسپذیر و قابل یکپارچهسازی با چرخه انتشار نرمافزار است.
|
||
</div>
|
||
|
||
<div class="section">
|
||
<div class="section-header">
|
||
<div class="section-number">۱</div>
|
||
<div class="section-title">
|
||
<h3>خلاصه اجرایی و انتخاب مسیر</h3>
|
||
<div class="subtitle">Executive Summary & Path Selection</div>
|
||
</div>
|
||
</div>
|
||
<div class="section-content">
|
||
<p>پیامرسان بله دو مسیر مجزا برای ارسال پیام ارائه میدهد. انتخاب مسیر صحیح، کلید موفقیت سناریوی «ارسال نوتیف به هر کاربر در هر زمان» است.</p>
|
||
<div class="comparison-grid">
|
||
<div class="comparison-card">
|
||
<h4>مسیر اول: Bot API استاندارد</h4>
|
||
<ul>
|
||
<li><span>آدرس پایه</span> <span class="value">tapi.bale.ai</span></li>
|
||
<li><span>هدفگیری</span> <span class="value">فقط Chat ID (کاربر باید بات را استارت کرده باشد)</span></li>
|
||
<li><span>هزینه</span> <span class="value">رایگان</span></li>
|
||
<li><span>مناسب برای</span> <span class="value" style="color: var(--warning);">تعامل دوطرفه و رباتهای خدماتی</span></li>
|
||
</ul>
|
||
</div>
|
||
<div class="comparison-card recommended">
|
||
<span class="card-badge">پیشنهاد ما ✓</span>
|
||
<h4>مسیر دوم: سرویس سفیر (Safir)</h4>
|
||
<ul>
|
||
<li><span>آدرس پایه</span> <span class="value">safir.bale.ai</span></li>
|
||
<li><span>هدفگیری</span> <span class="value">شماره موبایل (حتی بدون استارت بات)</span></li>
|
||
<li><span>هزینه</span> <span class="value">به ازای هر پیام (نیاز به شارژ اعتبار)</span></li>
|
||
<li><span>مناسب برای</span> <span class="value" style="color: var(--success);">ارسال نوتیفیکیشن، اعلان و OTP</span></li>
|
||
</ul>
|
||
</div>
|
||
</div>
|
||
<div class="highlight-box">
|
||
<strong>نتیجه کلیدی:</strong> برای سناریوی درخواستی شما (ارسال نوتیف به هر کاربر در هر زمان)، <strong>سرویس سفیر</strong> تنها گزینه عملیاتی است، زیرا وابستگی به `chat_id` و شروع گفتگو توسط کاربر را حذف میکند.
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="section">
|
||
<div class="section-header">
|
||
<div class="section-number">۲</div>
|
||
<div class="section-title">
|
||
<h3>گام اول: معماری و ساختار پروژه</h3>
|
||
<div class="subtitle">Architecture & Project Structure</div>
|
||
</div>
|
||
</div>
|
||
<div class="section-content">
|
||
<p>برای حفظ اصول Clean Architecture و قابلیت تستپذیری، پروژه به سه لایه اصلی تقسیم میشود:</p>
|
||
<div class="code-block">
|
||
<span class="comment">// ساختار پیشنهادی حل (Solution)</span>
|
||
BaleNotifier/
|
||
├── BaleNotifier.sln
|
||
├── src/
|
||
│ ├── BaleNotifier.Core/ <span class="comment">// مدلها (Models) و اینترفیسها (Interfaces)</span>
|
||
│ ├── BaleNotifier.Services/ <span class="comment">// پیادهسازی سرویسهای HTTP و منطق کسبوکار</span>
|
||
│ └── BaleNotifier.Worker/ <span class="comment">// Background Service برای Polling یا Console App</span>
|
||
└── tests/
|
||
└── BaleNotifier.Tests/ <span class="comment">// تستهای واحد (Unit Tests)</span>
|
||
</div>
|
||
<div class="info-box">
|
||
<strong>💡 تنظیمات پیکربندی (appsettings.json):</strong>
|
||
مقادیر `BotToken` و `ApiAccessKey` (دریافتی از پنل کسبوکار بله) باید در این فایل یا Azure Key Vault ذخیره شوند.
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="section">
|
||
<div class="section-header">
|
||
<div class="section-number">۳</div>
|
||
<div class="section-title">
|
||
<h3>گام دوم: پیادهسازی مدلها و سرویس سفیر</h3>
|
||
<div class="subtitle">Models & Safir Service Implementation</div>
|
||
</div>
|
||
</div>
|
||
<div class="section-content">
|
||
<p>سرویس سفیر نیازمند ارسال درخواستهای JSON با هدر احراز هویت خاص است. مدلهای زیر ساختار دادهای را تضمین میکنند:</p>
|
||
<div class="code-block">
|
||
<span class="keyword">public class</span> <span class="type">SafirSendRequest</span>
|
||
{
|
||
<span class="keyword">public string</span> RequestId { <span class="keyword">get</span>; <span class="keyword">set</span>; } = Guid.NewGuid().ToString(<span class="string">"N"</span>);
|
||
<span class="keyword">public long</span> BotId { <span class="keyword">get</span>; <span class="keyword">set</span>; }
|
||
<span class="keyword">public string</span> PhoneNumber { <span class="keyword">get</span>; <span class="keyword">set</span>; } = <span class="keyword">default!</span>;
|
||
<span class="keyword">public</span> <span class="type">SafirMessageData</span> MessageData { <span class="keyword">get</span>; <span class="keyword">set</span>; } = <span class="keyword">default!</span>;
|
||
}
|
||
|
||
<span class="keyword">public class</span> <span class="type">SafirMessageData</span>
|
||
{
|
||
<span class="keyword">public</span> <span class="type">SafirMessage</span>? Message { <span class="keyword">get</span>; <span class="keyword">set</span>; }
|
||
<span class="keyword">public bool</span>? IsSecure { <span class="keyword">get</span>; <span class="keyword">set</span>; } <span class="comment">// برای ارسال پیام رمزدار</span>
|
||
}
|
||
</div>
|
||
<p>پیادهسازی سرویس اصلی با استفاده از `HttpClient` و تزریق وابستگی (DI):</p>
|
||
<div class="code-block">
|
||
<span class="keyword">public class</span> <span class="type">SafirService</span> : <span class="type">ISafirService</span>
|
||
{
|
||
<span class="keyword">private readonly</span> <span class="type">HttpClient</span> _http;
|
||
<span class="keyword">private readonly</span> <span class="type">long</span> _botId;
|
||
|
||
<span class="keyword">public</span> <span class="type">SafirService</span>(<span class="type">HttpClient</span> http, <span class="type">IConfiguration</span> config)
|
||
{
|
||
_http = http;
|
||
_http.BaseAddress = <span class="keyword">new</span> <span class="type">Uri</span>(config[<span class="string">"Bale:Safir:BaseUrl"</span>]!);
|
||
_http.DefaultRequestHeaders.Add(<span class="string">"api-access-key"</span>, config[<span class="string">"Bale:Safir:ApiAccessKey"</span>]!);
|
||
_botId = <span class="keyword">long</span>.Parse(config[<span class="string">"Bale:Safir:BotId"</span>]!);
|
||
}
|
||
|
||
<span class="keyword">public async</span> <span class="type">Task</span><<span class="type">SafirSendResponse</span>?> <span class="type">SendTextNotificationAsync</span>(<span class="keyword">string</span> phone, <span class="keyword">string</span> text)
|
||
{
|
||
<span class="keyword">var</span> request = <span class="keyword">new</span> <span class="type">SafirSendRequest</span>
|
||
{
|
||
BotId = _botId,
|
||
PhoneNumber = <span class="type">NormalizePhoneNumber</span>(phone),
|
||
MessageData = <span class="keyword">new</span> <span class="type">SafirMessageData</span> { Message = <span class="keyword">new</span> <span class="type">SafirMessage</span> { Text = text } }
|
||
};
|
||
<span class="keyword">var</span> response = <span class="keyword">await</span> _http.PostAsJsonAsync(<span class="string">"/api/v3/send_message"</span>, request);
|
||
<span class="keyword">return await</span> response.Content.ReadFromJsonAsync<<span class="type">SafirSendResponse</span>>();
|
||
}
|
||
|
||
<span class="comment">// متد NormalizePhoneNumber برای اطمینان از فرمت 989123456789</span>
|
||
}
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="section">
|
||
<div class="section-header">
|
||
<div class="section-number">۴</div>
|
||
<div class="section-title">
|
||
<h3>گام سوم: مدیریت ارسال انبوه و Idempotency</h3>
|
||
<div class="subtitle">Bulk Management & Idempotency</div>
|
||
</div>
|
||
</div>
|
||
<div class="section-content">
|
||
<p>در محیط عملیاتی (Production)، ارسال نوتیفیکیشن باید در برابر خطاهای شبکه و تلاشهای تکراری (Retry) مقاوم باشد.</p>
|
||
<div class="success-box">
|
||
<strong>✓ مکانیزم Idempotency:</strong> فیلد `request_id` در درخواست سفیر، از ارسال تکراری پیام در صورتی که درخواست به دلیل خطای شبکه دوباره ارسال شود، جلوگیری میکند.
|
||
</div>
|
||
<div class="warning-box">
|
||
<strong>⚠️ مدیریت Rate Limit:</strong> سرویس بله دارای محدودیت نرخ ارسال است. در صورت ارسال انبوه، حتماً بین درخواستها تأخیر (Delay) ایجاد کنید یا از صفهای پیام (مانند Azure Service Bus یا RabbitMQ) با الگوی Consumer Rate Limiting استفاده نمایید.
|
||
</div>
|
||
<div class="code-block">
|
||
<span class="keyword">public async</span> <span class="type">Task</span> <span class="type">BroadcastAsync</span>(<span class="type">IEnumerable</span><<span class="keyword">string</span>> phones, <span class="keyword">string</span> text)
|
||
{
|
||
<span class="keyword">foreach</span> (<span class="keyword">var</span> phone <span class="keyword">in</span> phones)
|
||
{
|
||
<span class="keyword">await</span> _safir.SendTextNotificationAsync(phone, text);
|
||
<span class="keyword">await</span> <span class="type">Task</span>.Delay(200); <span class="comment">// جلوگیری از خطای RateLimitExceeded (کد 3)</span>
|
||
}
|
||
}
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="section">
|
||
<div class="section-header">
|
||
<div class="section-number">۵</div>
|
||
<div class="section-title">
|
||
<h3>گام چهارم: یکپارچهسازی با چرخه انتشار</h3>
|
||
<div class="subtitle">Integration with Release Pipeline</div>
|
||
</div>
|
||
</div>
|
||
<div class="section-content">
|
||
<p>به عنوان مدیر انتشار، میتوانید این سرویس را در نقاط مختلف چرخه ۷ مرحلهای انتشار (از ثبت درخواست تا استقرار آبی) فراخوانی کنید. نمونه استفاده در یک سرویس اعلان انتشار:</p>
|
||
<div class="code-block">
|
||
<span class="keyword">public class</span> <span class="type">ReleaseNotifier</span>
|
||
{
|
||
<span class="keyword">private readonly</span> <span class="type">INotificationService</span> _notifier;
|
||
|
||
<span class="keyword">public</span> <span class="type">ReleaseNotifier</span>(<span class="type">INotificationService</span> notifier) => _notifier = notifier;
|
||
|
||
<span class="keyword">public async</span> <span class="type">Task</span> <span class="type">OnReleaseDeployed</span>(<span class="keyword">string</span> version, <span class="type">IEnumerable</span><<span class="keyword">string</span>> stakeholderPhones)
|
||
{
|
||
<span class="keyword">var</span> message = $<span class="string">"✅ نسخه <b>{version}</b> با موفقیت در محیط عملیاتی آبی مستقر شد."</span>;
|
||
<span class="keyword">await</span> _notifier.BroadcastAsync(stakeholderPhones, message);
|
||
}
|
||
}
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="section">
|
||
<div class="section-header">
|
||
<div class="section-number">۶</div>
|
||
<div class="section-title">
|
||
<h3>مدیریت خطاها و نکات امنیتی</h3>
|
||
<div class="subtitle">Error Handling & Security Notes</div>
|
||
</div>
|
||
</div>
|
||
<div class="section-content">
|
||
<p>پاسخ سرویس سفیر شامل آرایهای از `error_data` است. پایش این کدها برای عیبیابی عملیاتی حیاتی است:</p>
|
||
<table class="styled-table">
|
||
<thead>
|
||
<tr>
|
||
<th>کد خطا</th>
|
||
<th>نام خطا</th>
|
||
<th>توضیح و راهحل</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td>3</td>
|
||
<td>RateLimitExceeded</td>
|
||
<td>بیش از حد مجاز پیام ارسال شده. افزایش Delay بین درخواستها.</td>
|
||
</tr>
|
||
<tr>
|
||
<td>8</td>
|
||
<td>InvalidPhone</td>
|
||
<td>فرمت شماره اشتباه است. اطمینان از حذف '0' اول و شروع با '98'.</td>
|
||
</tr>
|
||
<tr>
|
||
<td>17</td>
|
||
<td>NotBaleUser</td>
|
||
<td>کاربر با این شماره، حساب کاربری بله ندارد. حذف از لیست ارسال.</td>
|
||
</tr>
|
||
<tr>
|
||
<td>20</td>
|
||
<td>PaymentRequired</td>
|
||
<td>اعتبار پنل سفیر به پایان رسیده است. نیاز به شارژ حساب.</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
<div class="info-box">
|
||
<strong>🔒 نکته امنیتی:</strong> هرگز `ApiAccessKey` و `BotToken` را در مخزن کد (Git Repository) کامیت نکنید. از Azure Key Vault یا GitHub Secrets برای تزریق این مقادیر در زمان اجرا استفاده نمایید.
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="section">
|
||
<div class="section-header">
|
||
<div class="section-number">۷</div>
|
||
<div class="section-title">
|
||
<h3>جمعبندی نهایی و گام بعدی</h3>
|
||
<div class="subtitle">Final Summary & Next Steps</div>
|
||
</div>
|
||
</div>
|
||
<div class="section-content">
|
||
<div class="conclusion-box">
|
||
<h3>🎯 مسیر پیشنهادی</h3>
|
||
<p>برای دستیابی به هدف «ارسال نوتیف به هر کاربر در هر زمان»، پیادهسازی سرویس <strong>Safir</strong> با الگوی <strong>Background Worker</strong> و مدیریت صف، پایدارترین و حرفهایترین راهحل در اکوسیستم .NET است.</p>
|
||
<div class="highlight">
|
||
<strong>💎 ارزش فنی ارائهشده:</strong><br>
|
||
استقلال از Chat ID + مدیریت خودکار خطاها + یکپارچهسازی روان با چرخه انتشار + رعایت اصول Clean Architecture
|
||
</div>
|
||
</div>
|
||
<div class="info-box">
|
||
<strong>📞 گام بعدی:</strong> در صورت تأیید این معماری، میتوانم ریپازیتوری پایه (Boilerplate) شامل تمامی مدلها، سرویسها و تستهای واحد را آماده و در اختیار تیم توسعه قرار دهم.
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="page-info">
|
||
این مستند فنی محرمانه بوده و صرفاً جهت استفاده داخلی تیم توسعه و مدیریت انتشار شرکت رایان پرداز کاوش تهیه شده است.
|
||
</div>
|
||
</div>
|
||
<footer class="document-footer">
|
||
<div class="footer-brand">طراحی و تدوین: هادی خزاعی اصل | مدیر انتشار</div>
|
||
<div class="footer-divider"></div>
|
||
<div>تاریخ تهیه: آبان ۱۴۰۵ | نسخه: ۱.۰ | طبقهبندی: داخلی / فنی</div>
|
||
</footer>
|
||
</div>
|
||
</body>
|
||
</html> |