Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/conversation templates #44

Merged
merged 15 commits into from
Mar 20, 2024
Merged
2 changes: 1 addition & 1 deletion src/Sinch/Conversation/Messages/Message/TemplateMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public override string ToString()
sb.Append(" LanguageCode: ").Append(LanguageCode).Append("\n");
sb.Append(" Parameters: ").Append(Parameters).Append("\n");
sb.Append(" TemplateId: ").Append(TemplateId).Append("\n");
sb.Append(" VarVersion: ").Append(Version).Append("\n");
sb.Append(" Version: ").Append(Version).Append("\n");
sb.Append("}\n");
return sb.ToString();
}
Expand Down
21 changes: 15 additions & 6 deletions src/Sinch/Conversation/SinchConversationClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Sinch.Conversation.Contacts;
using Sinch.Conversation.Conversations;
using Sinch.Conversation.Messages;
using Sinch.Conversation.TemplatesV2;
using Sinch.Conversation.Webhooks;
using Sinch.Core;
using Sinch.Logger;
Expand Down Expand Up @@ -31,23 +32,29 @@ public interface ISinchConversation

/// <inheritdoc cref="ISinchConversationWebhooks" />
ISinchConversationWebhooks Webhooks { get; }

/// <inheritdoc cref="ISinchConversationTemplatesV2" />
ISinchConversationTemplatesV2 TemplatesV2 { get; }
}

/// <inheritdoc />
internal class SinchConversationClient : ISinchConversation
{
internal SinchConversationClient(string projectId, Uri baseAddress, LoggerFactory loggerFactory, IHttp http)
internal SinchConversationClient(string projectId, Uri conversationBaseAddress, Uri templatesBaseAddress
, LoggerFactory loggerFactory, IHttp http)
{
Messages = new Messages.Messages(projectId, baseAddress,
Messages = new Messages.Messages(projectId, conversationBaseAddress,
loggerFactory?.Create<ISinchConversationMessages>(),
http);
Apps = new Apps.Apps(projectId, baseAddress, loggerFactory?.Create<Apps.Apps>(), http);
Contacts = new Contacts.Contacts(projectId, baseAddress,
Apps = new Apps.Apps(projectId, conversationBaseAddress, loggerFactory?.Create<Apps.Apps>(), http);
Contacts = new Contacts.Contacts(projectId, conversationBaseAddress,
loggerFactory?.Create<ISinchConversationContacts>(), http);
Conversations = new ConversationsClient(projectId, baseAddress,
Conversations = new ConversationsClient(projectId, conversationBaseAddress,
loggerFactory?.Create<ISinchConversationConversations>(), http);
Webhooks = new Webhooks.Webhooks(projectId, baseAddress,
Webhooks = new Webhooks.Webhooks(projectId, conversationBaseAddress,
loggerFactory?.Create<ISinchConversationWebhooks>(), http);
TemplatesV2 = new TemplatesV2.TemplatesV2(projectId, templatesBaseAddress,
loggerFactory?.Create<ISinchConversationTemplatesV2>(), http);
}

/// <inheritdoc />
Expand All @@ -63,5 +70,7 @@ internal SinchConversationClient(string projectId, Uri baseAddress, LoggerFactor
public ISinchConversationConversations Conversations { get; }

public ISinchConversationWebhooks Webhooks { get; }

public ISinchConversationTemplatesV2 TemplatesV2 { get; }
}
}
41 changes: 41 additions & 0 deletions src/Sinch/Conversation/TemplatesV2/ChannelTemplateOverride.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System.Text;
using System.Text.Json.Serialization;
using Sinch.Conversation.Messages.Message;

namespace Sinch.Conversation.TemplatesV2
{
/// <summary>
/// Optional field to override the omnichannel template by referring to a channel-specific template.
/// </summary>
public sealed class ChannelTemplateOverride
{
/// <summary>
/// Gets or Sets Whatsapp
/// </summary>
[JsonPropertyName("WHATSAPP")]
public OverrideTemplateReference WhatsApp { get; set; }


/// <summary>
/// Gets or Sets Kakaotalk
/// </summary>
[JsonPropertyName("KAKAOTALK")]
public OverrideTemplateReference KakaoTalk { get; set; }


/// <summary>
/// Returns the string presentation of the object
/// </summary>
/// <returns>String presentation of the object</returns>
public override string ToString()
{
var sb = new StringBuilder();
sb.Append("class ChannelTemplateOverride {\n");
sb.Append(" WHATSAPP: ").Append(WhatsApp).Append("\n");
sb.Append(" KAKOTALK: ").Append(KakaoTalk).Append("\n");
sb.Append("}\n");
return sb.ToString();
}

}
}
70 changes: 70 additions & 0 deletions src/Sinch/Conversation/TemplatesV2/CreateTemplateRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Sinch.Conversation.TemplatesV2
{
public class CreateTemplateRequest
{
/// <summary>
/// The default translation to use if translation not specified. Specified as a BCP-47 &#x60;language_code&#x60; and the &#x60;language_code&#x60; must exist in the translations list.
/// </summary>
#if NET7_0_OR_GREATER
public required string DefaultTranslation { get; set; }
#else
public string DefaultTranslation { get; set; }
#endif

/// <summary>
/// Gets or Sets Translations
/// </summary>
#if NET7_0_OR_GREATER
public required List<TemplateTranslation> Translations { get; set; }
#else
public List<TemplateTranslation> Translations { get; set; }
#endif


/// <summary>
/// The description of the template.
/// </summary>
public string Description { get; set; }


/// <summary>
/// The version of the template. While creating a template, this will be defaulted to 1. When updating a template, you must supply the latest version of the template in order for the update to be successful.
/// </summary>
public int Version { get; set; }


/// <summary>
/// Timestamp when the template was created.
/// </summary>
public DateTime CreateTime { get; set; }


/// <summary>
/// Timestamp when the template was updated.
/// </summary>
public DateTime UpdateTime { get; set; }


/// <summary>
/// Returns the string presentation of the object
/// </summary>
/// <returns>String presentation of the object</returns>
public override string ToString()
{
var sb = new StringBuilder();
sb.Append("class V2TemplateResponse {\n");
sb.Append(" Description: ").Append(Description).Append("\n");
sb.Append(" Version: ").Append(Version).Append("\n");
sb.Append(" DefaultTranslation: ").Append(DefaultTranslation).Append("\n");
sb.Append(" Translations: ").Append(Translations).Append("\n");
sb.Append(" CreateTime: ").Append(CreateTime).Append("\n");
sb.Append(" UpdateTime: ").Append(UpdateTime).Append("\n");
sb.Append("}\n");
return sb.ToString();
}
}
}
32 changes: 32 additions & 0 deletions src/Sinch/Conversation/TemplatesV2/OverrideTemplateReference.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.Text;
using Sinch.Conversation.Messages.Message;

namespace Sinch.Conversation.TemplatesV2
{
public class OverrideTemplateReference
{
/// <summary>
/// The referenced template can be an omnichannel template stored in Conversation API Template Store as AppMessage or it can reference external channel-specific template such as WhatsApp Business Template.
/// </summary>
public TemplateReference TemplateReference { get; set; }

/// <summary>
/// Gets or Sets ParameterMappings
/// </summary>
public TemplateReferenceParameterMappings ParameterMappings { get; set; }

/// <summary>
/// Returns the string presentation of the object
/// </summary>
/// <returns>String presentation of the object</returns>
public override string ToString()
{
var sb = new StringBuilder();
sb.Append("class TemplateReference {\n");
sb.Append(" TemplateReference: ").Append(TemplateReference).Append("\n");
sb.Append(" ParameterMappings: ").Append(ParameterMappings).Append("\n");
sb.Append("}\n");
return sb.ToString();
}
}
}
73 changes: 73 additions & 0 deletions src/Sinch/Conversation/TemplatesV2/Template.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Sinch.Conversation.TemplatesV2
{
public class Template
{
/// <summary>
/// The id of the template. Specify this yourself during creation. Otherwise, we will generate an ID for you. This must
/// be unique for a given project.
/// </summary>
public string Id { get; set; }


/// <summary>
/// The description of the template.
/// </summary>
public string Description { get; set; }


/// <summary>
/// The version of the template. While creating a template, this will be defaulted to 1. When updating a template, you
/// must supply the latest version of the template in order for the update to be successful.
/// </summary>
public int Version { get; set; }


/// <summary>
/// The default translation to use if translation not specified. Specified as a BCP-47 &#x60;language_code&#x60; and
/// the &#x60;language_code&#x60; must exist in the translations list.
/// </summary>
public string DefaultTranslation { get; set; }


/// <summary>
/// Gets or Sets Translations
/// </summary>
public List<TemplateTranslation> Translations { get; set; }


/// <summary>
/// Timestamp when the template was created.
/// </summary>
public DateTime CreateTime { get; set; }


/// <summary>
/// Timestamp when the template was updated.
/// </summary>
public DateTime UpdateTime { get; set; }


/// <summary>
/// Returns the string presentation of the object
/// </summary>
/// <returns>String presentation of the object</returns>
public override string ToString()
{
var sb = new StringBuilder();
sb.Append("class V2TemplateResponse {\n");
sb.Append(" Id: ").Append(Id).Append("\n");
sb.Append(" Description: ").Append(Description).Append("\n");
sb.Append(" Version: ").Append(Version).Append("\n");
sb.Append(" DefaultTranslation: ").Append(DefaultTranslation).Append("\n");
sb.Append(" Translations: ").Append(Translations).Append("\n");
sb.Append(" CreateTime: ").Append(CreateTime).Append("\n");
sb.Append(" UpdateTime: ").Append(UpdateTime).Append("\n");
sb.Append("}\n");
return sb.ToString();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Text;

namespace Sinch.Conversation.TemplatesV2
{
/// <summary>
/// A mapping between omni-template variables and the channel specific parameters.
/// </summary>
public sealed class TemplateReferenceParameterMappings
{
/// <summary>
/// The mapping between the omni-template variable and the channel specific parameter.
/// </summary>
public string Name { get; set; }


/// <summary>
/// Returns the string presentation of the object
/// </summary>
/// <returns>String presentation of the object</returns>
public override string ToString()
{
var sb = new StringBuilder();
sb.Append("class TemplateReferenceParameterMappings {\n");
sb.Append(" Name: ").Append(Name).Append("\n");
sb.Append("}\n");
return sb.ToString();
}

}

}
Loading
Loading