Skip to content

Commit

Permalink
Feat/conversation templates (#44)
Browse files Browse the repository at this point in the history
* feat: implement get, list, create, delete, update, list translations endpoints

* refactor: rename all VarVersion to Version in toString
  • Loading branch information
Dovchik authored Mar 20, 2024
1 parent 58b2ece commit 3042176
Show file tree
Hide file tree
Showing 18 changed files with 875 additions and 18 deletions.
28 changes: 19 additions & 9 deletions src/Sinch/Conversation/SinchConversationClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Sinch.Conversation.Events;
using Sinch.Conversation.Messages;
using Sinch.Conversation.Transcoding;
using Sinch.Conversation.TemplatesV2;
using Sinch.Conversation.Webhooks;
using Sinch.Core;
using Sinch.Logger;
Expand Down Expand Up @@ -43,28 +44,34 @@ public interface ISinchConversation

/// <inheritdoc cref="ISinchConversationCapabilities" />
ISinchConversationCapabilities Capabilities { 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);
Events = new Events.Events(projectId, baseAddress, loggerFactory?.Create<ISinchConversationEvents>(), http);
Transcoding = new Transcoding.Transcoding(projectId, baseAddress,
Events = new Events.Events(projectId, conversationBaseAddress, loggerFactory?.Create<ISinchConversationEvents>(), http);
Transcoding = new Transcoding.Transcoding(projectId, conversationBaseAddress,
loggerFactory?.Create<ISinchConversationTranscoding>(), http);
Capabilities = new Capabilities(projectId, baseAddress,
Capabilities = new Capabilities(projectId, conversationBaseAddress,
loggerFactory?.Create<ISinchConversationCapabilities>(), http);
TemplatesV2 = new TemplatesV2.TemplatesV2(projectId, templatesBaseAddress,
loggerFactory?.Create<ISinchConversationTemplatesV2>(), http);
}

/// <inheritdoc />
Expand All @@ -90,5 +97,8 @@ internal SinchConversationClient(string projectId, Uri baseAddress, LoggerFactor

/// <inheritdoc />
public ISinchConversationCapabilities Capabilities { get; }

/// <inheritdoc />
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

0 comments on commit 3042176

Please sign in to comment.