Skip to content

Commit 504a506

Browse files
authored
Merge pull request #1 from PandaTechAM/email-sms-implementation
Email sms implementation
2 parents 5c3a7fa + 44e01d6 commit 504a506

30 files changed

+918
-59
lines changed

Readme.md

Lines changed: 170 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,182 @@
1-
# Pandatech.Communicator
1+
# 1. PandaTech.Communicator
22

3-
## Introduction
3+
- [1. EasyRateLimiter](#1-easyratelimiter)
4+
- [1.1. Introduction](#11-introduction)
5+
- [1.2. Installation](#12-installation)
6+
- [1.3. Setup](#13-setup)
7+
- [1.3.1. Program.cs Example](#131-programcs-example)
8+
- [1.3.2. Appsettings.json Example](#132-appsettingsjson-example)
9+
- [1.4. Configuration Options Explained](#14-configuration-options-explained)
10+
- [1.5. Limitations](#15-limitations)
11+
- [1.6. License](#16-license)
412

5-
This nuget is fake for now. Under development.
13+
## 1.1. Introduction
14+
**PandaTech.Communicator** is aimed to send Email and SMS messages to the clients of your service where you use this library.
615

16+
- **Email:** By given setup it's easy and fast to configure and setup Email providers for later use by different channels.
17+
- **SMS:** By given setup it's easy and fast to configure and setup already integrated SMS providers for later use by different channels.
18+
- **Dexatel**
19+
- **Twilio**
720

8-
## Features
21+
This package is ideal for efficient and reliable messaging in any application.
922

23+
## 1.2. Installation
1024

11-
## Installation
25+
Install this NuGet library directly from the IDE package installer or by following command:
1226

27+
`dotnet add package PandaTech.Communicator`
1328

29+
## 1.3. Setup
1430

15-
## Usage
31+
To incorporate PandaTech.Communicator into your project, you have a primary method to setup in your `Program.cs`:
1632

33+
`builder.AddPandaCommunicator();`
1734

18-
## License
35+
Configuration options can be specified either in `appsettings.json` or directly in `Program.cs`, with the latter taking precedence.
1936

20-
Pandatech.Communicator is licensed under the MIT License.
37+
### 1.3.1. Program.cs Example
38+
39+
In case of using SSL by setting UseSsl = true use port number 456, otherwise use 587 for non SSL connection.
40+
41+
```csharp
42+
builder.AddPandaCommunicator(options =>
43+
{
44+
options.SmsFake = false;
45+
options.SmsConfigurations =
46+
[
47+
new SmsConfiguration
48+
{
49+
Provider = "Dexatel",
50+
BaseUrl = "https://api.dexatel.com",
51+
From = "sender_name",
52+
Properties = new()
53+
{
54+
{ "X-Dexatel-Key", "key" }
55+
},
56+
TimeoutMs = 10000,
57+
Channel = "GeneralSender"
58+
},
59+
60+
new SmsConfiguration
61+
{
62+
Provider = "Twilio",
63+
BaseUrl = "https://api.twilio.com",
64+
From = "sender_number",
65+
Properties = new()
66+
{
67+
{ "SID", "key" },
68+
{ "AUTH_TOKEN", "token" }
69+
},
70+
TimeoutMs = 10000,
71+
Channel = "TransactionalSender"
72+
}
73+
];
74+
options.EmailFake = false;
75+
options.EmailConfigurations =
76+
[
77+
new EmailConfiguration
78+
{
79+
SmtpServer = "smtp.test.com",
80+
SmtpPort = 465, // 587
81+
SmtpUsername = "test",
82+
SmtpPassword = "test123",
83+
SenderEmail = "[email protected]",
84+
UseSsl = true, // false
85+
TimeoutMs = 10000,
86+
Channel = "GeneralSender"
87+
},
88+
89+
new EmailConfiguration
90+
{
91+
SmtpServer = "smtp.gmail.com",
92+
SmtpPort = 465, // 587
93+
SmtpUsername = "vazgen",
94+
SmtpPassword = "vazgen123",
95+
SenderEmail = "[email protected]",
96+
UseSsl = true, // false
97+
TimeoutMs = 10000,
98+
Channel = "TransactionalSender"
99+
}
100+
];
101+
});
102+
103+
```
104+
105+
### 1.3.2. Appsettings.json Example
106+
107+
```json
108+
{
109+
"Logging": {
110+
"LogLevel": {
111+
"Default": "Information",
112+
"Microsoft.AspNetCore": "Warning"
113+
}
114+
},
115+
"PandaCommunicator": {
116+
"SmsFake": false,
117+
"SmsConfigurationOptions": [
118+
{
119+
"Provider": "Dexatel",
120+
"BaseUrl": "https://api.dexatel.com",
121+
"From": "sender_name",
122+
"Properties": {
123+
"X-Dexatel-Key": "key"
124+
},
125+
"TimeoutMs": "10000",
126+
"Channel": "GeneralSender"
127+
},
128+
{
129+
"Provider": "Twilio",
130+
"BaseUrl": "https://api.twilio.com",
131+
"From": "twilio_sender_number",
132+
"Properties": {
133+
"SID": "key",
134+
"AUTH_TOKEN": "token"
135+
},
136+
"TimeoutMs": "10000",
137+
"Channel": "TransactionalSender"
138+
}
139+
],
140+
"EmailFake": false,
141+
"EmailConfigurationOptions": [
142+
{
143+
"SmtpServer": "smtp.gmail.com",
144+
"SmtpPort": "465", // 587
145+
"SmtpUsername": "test",
146+
"SmtpPassword": "test123",
147+
"SenderEmail": "[email protected]",
148+
"UseSsl": "true", // false
149+
"TimeoutMs": "10000",
150+
"Channel": "GeneralSender"
151+
},
152+
{
153+
"SmtpServer": "smtp.gmail.com",
154+
"SmtpPort": "465", // 587
155+
"SmtpUsername": "vazgen",
156+
"SmtpPassword": "vazgen123",
157+
"SenderEmail": "[email protected]",
158+
"UseSsl": "true", // false
159+
"TimeoutMs": "10000",
160+
"Channel": "TransactionalSender"
161+
}
162+
]
163+
}
164+
}
165+
```
166+
The configuration options in `appsettings.json` and `program.cs` (priority) are identical.
167+
168+
## 1.4. Configuration Options Explained
169+
170+
- **PandaCommunicator:** Global settings for PandaTech.Communicator
171+
- **SmsFake:** This setup is for fake SMS service to be used which doesn't send real SMS messages and just return `TTask.CompletedTask`.
172+
- **SmsConfigurations:** SMS configurations given by `appsettings.json` or via `builder.AddPandaCommunicator()` options for SMS.
173+
- **EmailFake:** This setup is for fake Email service to be used which doesn't send real SMS messages and just return `TTask.CompletedTask`.
174+
- **EmailConfigurations:** Email configurations given by `appsettings.json` or via `builder.AddPandaCommunicator()` options for Email.
175+
176+
## 1.5. Limitations
177+
178+
PandaTech.Communicator works with all Email providers, but with only with existing integrations for SMS listed above.
179+
180+
## 1.6. License
181+
182+
PandaTech.Communicator is licensed under the MIT License.
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
namespace Communicator.Demo.MessageTemplates;
2+
3+
public static class EmailTemplates
4+
{
5+
private const string ServiceName = "PandaTech.Communicator";
6+
private const string CompanyName = "PandaTech";
7+
private const string Minutes = "15";
8+
private const string Hours = "24";
9+
10+
private const string GreenButtonStyle = """
11+
.button {
12+
background-color: #4CAF50;
13+
border: none;
14+
color: white;
15+
padding: 15px 32px;
16+
text-align: center;
17+
text-decoration: none;
18+
display: inline-block;
19+
font-size: 16px;
20+
margin: 4px 2px;
21+
cursor: pointer;
22+
border-radius: 25px;
23+
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
24+
transition: 0.3s;
25+
}
26+
.button:hover {
27+
background-color: #45a049;
28+
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2);
29+
}
30+
""";
31+
32+
private const string RedButtonStyle = """
33+
.button {
34+
background-color: #D9534F; /* Bootstrap's btn-danger */
35+
border: none;
36+
color: white;
37+
padding: 15px 32px;
38+
text-color: white;
39+
text-align: center;
40+
text-decoration: none;
41+
display: inline-block;
42+
font-size: 16px;
43+
margin: 4px 2px;
44+
cursor: pointer;
45+
border-radius: 25px;
46+
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
47+
transition: 0.3s;
48+
}
49+
.button:hover {
50+
background-color: #C9302C; /* Darker shade of red for hover effect */
51+
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2);
52+
}
53+
""";
54+
55+
public static string AddEmailAddressTemplate(string firstName, string lastName, string link)
56+
{
57+
return $$"""
58+
<!DOCTYPE html>
59+
<html>
60+
<head>
61+
<style>
62+
body { font-family: 'Arial'; }
63+
{{GreenButtonStyle}}
64+
</style>
65+
</head>
66+
<body>
67+
<p>Hello {{FullName(firstName, lastName)}},</p>
68+
<p>You have requested to add a new email address to your {{ServiceName}} account. To confirm and complete this action, please click the button below:</p>
69+
<a href='{{link}}' class='button'>Add Email Address</a>
70+
<p>This link will expire in {{Minutes}} minutes. If you did not request this change or if it was made by mistake, no action is needed.</p>
71+
<p>If you're having trouble clicking the "Add Email Address" button, copy and paste the URL below into your web browser:</p>
72+
<p><a href='{{link}}'>{{link}}</a></p>
73+
<p>Thank you for updating your account,</p>
74+
<p>The {{CompanyName}} Team</p>
75+
</body>
76+
</html>
77+
""";
78+
}
79+
80+
private static string FullName(string firstName, string lastName)
81+
{
82+
return $"{firstName} {lastName}".Trim();
83+
}
84+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace Communicator.Demo.MessageTemplates;
2+
3+
public static class SmsTemplates
4+
{
5+
private const string ServiceName = "PandaTech.Communicator";
6+
7+
public static string OtpCodeVerificationRequestMessage(string otpCode)
8+
{
9+
return
10+
$"Code: {otpCode} is your {ServiceName} verification code to verify your new phone number in the system. Do not share this code.";
11+
}
12+
}

0 commit comments

Comments
 (0)