Skip to content

Commit 1bf05bd

Browse files
committed
Adding AMP support to injectionApi and examples
1 parent 744e04c commit 1bf05bd

File tree

12 files changed

+329
-14
lines changed

12 files changed

+329
-14
lines changed

Example Projects/dotNetCoreExample/Examples/Basic/BasicComplexExample.cs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,36 @@ public SendResponse RunExample()
1010
{
1111
var client = new SocketLabsClient(ExampleConfig.ServerId, ExampleConfig.ApiKey);
1212

13+
// Build the message
1314
var message = new BasicMessage();
1415

15-
message.To.Add("recipient1@example.com");
16-
message.To.Add("recipient2@example.com", "Recipient #2");
17-
1816
message.Subject = "Sending Basic Complex Example";
1917
message.HtmlBody = "<body><p><strong>Lorem Ipsum</strong></p><br /><img src=\"cid:Bus\" /></body>";
2018
message.PlainTextBody = "Lorem Ipsum";
19+
message.AmpBody = "<!doctype html>" +
20+
"<html amp4email>" +
21+
"<head>" +
22+
" <meta charset=\"utf-8\">" +
23+
" <script async src=\"https://cdn.ampproject.org/v0.js\"></script>" +
24+
" <style amp4email-boilerplate>body{visibility:hidden}</style>" +
25+
" <style amp-custom>" +
26+
" h1 {" +
27+
" margin: 1rem;" +
28+
" }" +
29+
" </style>" +
30+
"</head>" +
31+
"<body>" +
32+
" <h1>This is the AMP Html Body of my message</h1>" +
33+
"</body>" +
34+
"</html>";
35+
2136
message.CharSet = "utf-8";
2237

38+
// Add recipients
39+
message.To.Add("recipient1@example.com");
40+
message.To.Add("recipient2@example.com", "Recipient #2");
41+
42+
// Set other properties as needed
2343
message.From.Email = "from@example.com";
2444
message.ReplyTo.Email = "replyto@example.com";
2545

@@ -31,6 +51,7 @@ public SendResponse RunExample()
3151
var attachment = message.Attachments.Add("bus.png", MimeType.PNG, @".\examples\img\bus.png");
3252
attachment.ContentId = "Bus";
3353

54+
// Send the message
3455
return client.Send(message);
3556
}
3657
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using SocketLabs.InjectionApi;
2+
using SocketLabs.InjectionApi.Message;
3+
4+
namespace dotNetCoreExample.Examples.Basic
5+
{
6+
public class BasicSendWithAmpBody : IExample
7+
{
8+
public SendResponse RunExample()
9+
{
10+
var client = new SocketLabsClient(ExampleConfig.ServerId, ExampleConfig.ApiKey)
11+
{
12+
EndpointUrl = ExampleConfig.TargetApi
13+
};
14+
15+
// Build the message
16+
var message = new BasicMessage();
17+
18+
message.Subject = "Sending A Test Message";
19+
message.HtmlBody = "<html>This Html text will show if Amp is not supported/not implemented properly.</html>";
20+
message.AmpBody = "<!doctype html>" +
21+
"<html amp4email>" +
22+
"<head>" +
23+
" <meta charset=\"utf-8\">" +
24+
" <script async src=\"https://cdn.ampproject.org/v0.js\"></script>" +
25+
" <style amp4email-boilerplate>body{visibility:hidden}</style>" +
26+
" <style amp-custom>" +
27+
" h1 {" +
28+
" margin: 1rem;" +
29+
" }" +
30+
" </style>" +
31+
"</head>" +
32+
"<body>" +
33+
" <h1>This is the AMP Html Body of my message</h1>" +
34+
"</body>" +
35+
"</html>";
36+
37+
38+
39+
40+
// Add recipients
41+
message.To.Add("recipient1@example.com");
42+
message.To.Add("recipient2@example.com", "Recipient #2");
43+
message.To.Add(new EmailAddress("recipient3@example.com"));
44+
message.To.Add(new EmailAddress("recipient4@example.com", "Recipient #4"));
45+
46+
// Set other properties as needed
47+
message.From.Email = "from@example.com";
48+
message.ReplyTo.Email = "replyto@example.com";
49+
50+
//Send message
51+
return client.Send(message);
52+
}
53+
}
54+
}

Example Projects/dotNetCoreExample/Examples/Bulk/BulkSendComplexExample.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,39 @@ public SendResponse RunExample()
6767
html.AppendLine("</html>");
6868
message.HtmlBody = html.ToString();
6969

70+
// Amp Body option
71+
var amp = new StringBuilder();
72+
amp.AppendLine("<!doctype html>");
73+
amp.AppendLine("<html amp4email>");
74+
amp.AppendLine(" <head><title>Complex AMP Email</title><meta charset=\"utf-8\">");
75+
amp.AppendLine(" <script async src=\"https://cdn.ampproject.org/v0.js\"></script>");
76+
amp.AppendLine(" <style amp4email-boilerplate>body{visibility:hidden}</style>");
77+
amp.AppendLine(" <style amp-custom>");
78+
amp.AppendLine(" h1 {");
79+
amp.AppendLine(" margin: 1rem;");
80+
amp.AppendLine(" }");
81+
amp.AppendLine(" </style></head>");
82+
amp.AppendLine(" <body>");
83+
amp.AppendLine(" <h1>AMP Is Enabled</h1>");
84+
amp.AppendLine(" <h1>Merged Data</h1>");
85+
amp.AppendLine(" <p>");
86+
amp.AppendLine(" Motto = <b>%%Motto%%</b> </br>");
87+
amp.AppendLine(" Birthday = <b>%%Birthday%%</b> </br>");
88+
amp.AppendLine(" Age = <b>%%Age%%</b> </br>");
89+
amp.AppendLine(" UpSell = <b>%%UpSell%%</b> </br>");
90+
amp.AppendLine(" </p>");
91+
amp.AppendLine(" </br>");
92+
amp.AppendLine(" <h1>Example of Merge Usage</h1>");
93+
amp.AppendLine(" <p>");
94+
amp.AppendLine(" Our company motto is '<b>%%Motto%%</b>'. </br>");
95+
amp.AppendLine(" Your birthday is <b>%%Birthday%%</b> and you are <b>%%Age%%</b> years old. </br>");
96+
amp.AppendLine(" </br>");
97+
amp.AppendLine(" <b>%%UpSell%%<b>");
98+
amp.AppendLine(" </p>");
99+
amp.AppendLine(" </body>");
100+
amp.AppendLine("</html>");
101+
message.AmpBody = amp.ToString();
102+
70103
message.PlainTextBody = Regex.Replace(message.HtmlBody, "<.*?>", string.Empty);
71104

72105
// Add an Attachment with a custom header
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using SocketLabs.InjectionApi;
2+
using SocketLabs.InjectionApi.Message;
3+
4+
namespace dotNetCoreExample.Examples.Bulk
5+
{
6+
public class BulkSendWithAmpBody : IExample
7+
{
8+
public SendResponse RunExample()
9+
{
10+
var client = new SocketLabsClient(ExampleConfig.ServerId, ExampleConfig.ApiKey)
11+
{
12+
EndpointUrl = ExampleConfig.TargetApi
13+
};
14+
15+
// Build the message
16+
var message = new BulkMessage();
17+
18+
message.Subject = "Sending A Test Message";
19+
// HtmlBody will be shown if Amp is not supported/not implemented properly
20+
message.HtmlBody = "<html>This Html Body of my message.</html>";
21+
message.AmpBody = "<!doctype html>" +
22+
"<html amp4email>" +
23+
"<head>" +
24+
" <meta charset=\"utf-8\">" +
25+
" <script async src=\"https://cdn.ampproject.org/v0.js\"></script>" +
26+
" <style amp4email-boilerplate>body{visibility:hidden}</style>" +
27+
" <style amp-custom>" +
28+
" h1 {" +
29+
" margin: 1rem;" +
30+
" }" +
31+
" </style>" +
32+
"</head>" +
33+
"<body>" +
34+
" <h1>This is the AMP Html Body of my message</h1>" +
35+
"</body>" +
36+
"</html>";
37+
38+
// Add recipients
39+
message.To.Add("recipient1@example.com");
40+
message.To.Add("recipient2@example.com", "Recipient #2");
41+
message.To.Add(new BulkRecipient("recipient3@example.com"));
42+
message.To.Add(new BulkRecipient("recipient4@example.com", "Recipient #4"));
43+
44+
// Set other properties as needed
45+
message.From.Email = "from@example.com";
46+
message.ReplyTo.Email = "replyto@example.com";
47+
48+
// Send message
49+
return client.Send(message);
50+
}
51+
}
52+
}

Example Projects/dotNetCoreExample/Program.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ private static void DisplayTheMenu()
6767
Console.WriteLine(" 16: Bulk Send From DataSource With MergeData ");
6868
Console.WriteLine(" 17: Bulk Send Complex Example (Everything including the Kitchen Sink) ");
6969
Console.WriteLine();
70+
Console.WriteLine(" Amp Examples: ");
71+
Console.WriteLine(" 18: Basic Send With Amp Body ");
72+
Console.WriteLine(" 19: Bulk Send With Amp Body ");
73+
Console.WriteLine();
7074
Console.WriteLine("-------------------------------------------------------------------------");
7175
}
7276

@@ -97,6 +101,9 @@ private static string GetExampleName(string selection)
97101
case 15: return "dotNetCoreExample.Examples.Bulk.BulkSendWithAsciiCharsetMergeData";
98102
case 16: return "dotNetCoreExample.Examples.Bulk.BulkSendFromDataSourceWithMerge";
99103
case 17: return "dotNetCoreExample.Examples.Bulk.BulkSendComplexExample";
104+
case 18: return "dotNetCoreExample.Examples.Basic.BasicSendWithAmpBody";
105+
case 19: return "dotNetCoreExample.Examples.Bulk.BulkSendWithAmpBody";
106+
100107
default:
101108
Console.WriteLine("Invalid Input (Out of Range)");
102109
return null;

src/SocketLabs/InjectionApi/Core/InjectionRequestFactory.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ internal virtual MessageJson GenerateBaseMessageJson(IMessageBase message)
8686
Subject = message.Subject,
8787
TextBody = message.PlainTextBody,
8888
HtmlBody = message.HtmlBody,
89+
AmpBody = message.AmpBody,
8990
MailingId = message.MailingId,
9091
MessageId = message.MessageId,
9192
CharSet = message.CharSet,

src/SocketLabs/InjectionApi/Core/SendValidator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ internal virtual bool HasFromAddress(IMessageBase message)
111111
/// Check if the message has a Message Body
112112
/// </summary>
113113
/// <remarks>
114-
/// If an Api Template is specified it will override the HtmlBody and/or the PlainTextBody.
115-
/// If no Api Template is specified the HtmlBody and/or the PlainTextBody must me set
114+
/// If an Api Template is specified it will override the HtmlBody, the AmpBody and/or the PlainTextBody.
115+
/// If no Api Template is specified the HtmlBody and/or the PlainTextBody must be set
116116
/// </remarks>
117117
/// <param name="message">The base interface, <c>IMessageBase</c>, of the message to be sent.</param>
118118
/// <returns><c>bool</c> result</returns>

src/SocketLabs/InjectionApi/Core/Serialization/MessageJson.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ public MessageJson()
4747
/// </summary>
4848
public string HtmlBody { get; set; }
4949

50+
/// <summary>
51+
/// Gets or sets the AMP portion of the message body.
52+
/// </summary>
53+
public string AmpBody { get; set; }
54+
5055
/// <summary>
5156
/// Gets or sets the Api Template for the message.
5257
/// </summary>

src/SocketLabs/InjectionApi/Message/BasicMessage.cs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,22 @@ namespace SocketLabs.InjectionApi.Message
1313
///
1414
/// message.PlainTextBody = "This is the body of my message sent to ##Name##";
1515
/// message.HtmlBody = "<![CDATA[ <html> ]]>This is the HtmlBody of my message sent to ##Name##<![CDATA[ </html> ]]>";
16+
/// message.AmpBody("<!doctype html>" +
17+
///"<html amp4email>" +
18+
///"<head>" +
19+
///" <meta charset=\"utf-8\">" +
20+
///" <script async src=\"https://cdn.ampproject.org/v0.js\"></script>" +
21+
///" <style amp4email-boilerplate>body{visibility:hidden}</style>" +
22+
///" <style amp-custom>" +
23+
///" h1 {" +
24+
///" margin: 1rem;" +
25+
///" }" +
26+
///" </style>" +
27+
///"</head>" +
28+
///"<body>" +
29+
///" <h1>This is the AMP Html Body of my message</h1>" +
30+
///"</body>" +
31+
///"</html>");
1632
/// message.Subject = "Sending a test message";
1733
/// message.From.Email = "from@example.com";
1834
///
@@ -25,6 +41,7 @@ namespace SocketLabs.InjectionApi.Message
2541
/// </example>
2642
/// <seealso cref="IMessageBase"/>
2743
/// <seealso cref="IBasicMessage"/>
44+
2845
public class BasicMessage : IBasicMessage
2946
{
3047
/// <summary>
@@ -40,7 +57,7 @@ public class BasicMessage : IBasicMessage
4057
/// </summary>
4158
/// <remarks>
4259
/// (Optional)
43-
/// Either PlainTextBody or HtmlBody must be used or use a ApiTemplate
60+
/// Either PlainTextBody or HtmlBody must be used or use a ApiTemplate with the AmpBody
4461
/// </remarks>
4562
public string PlainTextBody { get; set; }
4663

@@ -49,16 +66,26 @@ public class BasicMessage : IBasicMessage
4966
/// </summary>
5067
/// <remarks>
5168
/// (Optional)
52-
/// Either PlainTextBody or HtmlBody must be used or use a ApiTemplate
69+
/// Either PlainTextBody or HtmlBody must be used or use a ApiTemplate with the AmpBody
5370
/// </remarks>
5471
public string HtmlBody { get; set; }
5572

73+
/// <summary>
74+
/// Gets or sets the AMP portion of the message body.
75+
/// </summary>
76+
/// <remarks>
77+
/// (Optional)
78+
/// Either PlainTextBody or HtmlBody must be used or use a ApiTemplate with the AmpBody with the AmpBody
79+
/// See https://amp.dev/documentation/ for more information on AMP implementation
80+
/// </remarks>
81+
public string AmpBody { get; set; }
82+
5683
/// <summary>
5784
/// Gets or sets the Api Template for the message.
5885
/// </summary>
5986
/// <remarks>
6087
/// (Optional)
61-
/// Either PlainTextBody or HtmlBody must be used or use a ApiTemplate
88+
/// Either PlainTextBody or HtmlBody must be used or use a ApiTemplate with the AmpBody
6289
/// </remarks>
6390
public int? ApiTemplate { get; set; }
6491

src/SocketLabs/InjectionApi/Message/BulkMessage.cs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,22 @@ namespace SocketLabs.InjectionApi.Message
1414
///
1515
/// message.PlainTextBody = "This is the body of my message sent to ##Name##";
1616
/// message.HtmlBody = "<![CDATA[ <html> ]]>This is the HtmlBody of my message sent to ##Name##<![CDATA[ </html> ]]>";
17+
/// message.AmpBody("<!doctype html>" +
18+
///"<html amp4email>" +
19+
///"<head>" +
20+
///" <meta charset=\"utf-8\">" +
21+
///" <script async src=\"https://cdn.ampproject.org/v0.js\"></script>" +
22+
///" <style amp4email-boilerplate>body{visibility:hidden}</style>" +
23+
///" <style amp-custom>" +
24+
///" h1 {" +
25+
///" margin: 1rem;" +
26+
///" }" +
27+
///" </style>" +
28+
///"</head>" +
29+
///"<body>" +
30+
///" <h1>This is the AMP Html Body of my message</h1>" +
31+
///"</body>" +
32+
///"</html>");
1733
/// message.Subject = "Sending a test message";
1834
/// message.From.Email = "from@example.com";
1935
///
@@ -46,7 +62,7 @@ public class BulkMessage : IBulkMessage
4662
/// </summary>
4763
/// <remarks>
4864
/// (Optional)
49-
/// Either PlainTextBody or HtmlBody must be used or use a ApiTemplate
65+
/// Either PlainTextBody or HtmlBody must be used or use a ApiTemplate with the AmpBody
5066
/// </remarks>
5167
public string PlainTextBody { get; set; }
5268

@@ -55,16 +71,26 @@ public class BulkMessage : IBulkMessage
5571
/// </summary>
5672
/// <remarks>
5773
/// (Optional)
58-
/// Either PlainTextBody or HtmlBody must be used or use a ApiTemplate
74+
/// Either PlainTextBody or HtmlBody must be used or use a ApiTemplate with the AmpBody
5975
/// </remarks>
6076
public string HtmlBody { get; set; }
6177

78+
/// <summary>
79+
/// Gets or sets the AMP HTML portion of the message body.
80+
/// </summary>
81+
/// <remarks>
82+
/// (Optional)
83+
/// Either PlainTextBody or HtmlBody must be used or use a ApiTemplate with the AmpBody with the AmpBody
84+
/// See https://amp.dev/documentation/ for more information on AMP implementation
85+
/// </remarks>
86+
public string AmpBody { get; set; }
87+
6288
/// <summary>
6389
/// Gets or sets the Api Template for the message.
6490
/// </summary>
6591
/// <remarks>
6692
/// (Optional)
67-
/// Either PlainTextBody or HtmlBody must be used or use a ApiTemplate
93+
/// Either PlainTextBody or HtmlBody must be used or use a ApiTemplate with the AmpBody
6894
/// </remarks>
6995
public int? ApiTemplate { get; set; }
7096

0 commit comments

Comments
 (0)