-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat/conversation event transcoding capability endpoints (#43)
* refactor: make identities common * feat: implement Events, transcoding add capabilities * chore: add APPLEBC to ConversationChannel.cs * chore: move out capabilities * chore: clean Var{property} from toStrings * refactor: harmonize exception message between injectEvent and injectMessage
- Loading branch information
Showing
61 changed files
with
1,641 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System; | ||
using System.Net.Http; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Sinch.Core; | ||
using Sinch.Logger; | ||
|
||
namespace Sinch.Conversation.Capability | ||
{ | ||
/// <summary> | ||
/// A capability query checks the options available for reaching the | ||
/// [contact](https://developers.sinch.com/docs/conversation/keyconcepts/#contact) | ||
/// on the channels on which it has a channel identity. | ||
/// Capability queries can only be executed for contacts that already exist in a project and app. | ||
/// For executing the request, either the contact ID or the channel recipient identities of the contact are required. | ||
/// The request is executed asynchronously, therefore the service responds immediately. | ||
/// The result of the capability query is sent to the registered webhook for the CAPABILITY trigger. | ||
/// </summary> | ||
public interface ISinchConversationCapabilities | ||
{ | ||
/// <summary> | ||
/// This method is asynchronous - it immediately returns the requested Capability registration. | ||
/// Capability check is then delivered as a callback to registered webhooks with trigger | ||
/// CAPABILITY for every reachable channel. | ||
/// </summary> | ||
/// <param name="request"></param> | ||
/// <param name="cancellationToken"></param> | ||
/// <returns></returns> | ||
Task<LookupCapabilityResponse> Lookup(LookupCapabilityRequest request, | ||
CancellationToken cancellationToken = default); | ||
} | ||
|
||
internal class Capabilities : ISinchConversationCapabilities | ||
{ | ||
private readonly Uri _baseAddress; | ||
private readonly IHttp _http; | ||
private readonly ILoggerAdapter<ISinchConversationCapabilities> _logger; | ||
private readonly string _projectId; | ||
|
||
public Capabilities(string projectId, Uri baseAddress, ILoggerAdapter<ISinchConversationCapabilities> logger, | ||
IHttp http) | ||
{ | ||
_projectId = projectId; | ||
_baseAddress = baseAddress; | ||
_http = http; | ||
_logger = logger; | ||
} | ||
|
||
public Task<LookupCapabilityResponse> Lookup(LookupCapabilityRequest request, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
var uri = new Uri(_baseAddress, $"v1/projects/{_projectId}/capability:query"); | ||
_logger?.LogDebug("Looking up for a capability..."); | ||
return _http.Send<LookupCapabilityRequest, LookupCapabilityResponse>(uri, HttpMethod.Post, request, | ||
cancellationToken); | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/Sinch/Conversation/Capability/LookupCapabilityRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using Sinch.Conversation.Common; | ||
|
||
namespace Sinch.Conversation.Capability | ||
{ | ||
public class LookupCapabilityRequest | ||
{ | ||
/// <summary> | ||
/// The ID of the app to use for capability lookup. | ||
/// </summary> | ||
#if NET7_0_OR_GREATER | ||
public required string AppId { get; set; } | ||
#else | ||
public string AppId { get; set; } | ||
#endif | ||
|
||
/// <summary> | ||
/// The recipient to lookup capabilities for. Requires either contact_id or identified_by. | ||
/// </summary> | ||
#if NET7_0_OR_GREATER | ||
public required IRecipient Recipient { get; set; } | ||
#else | ||
public IRecipient Recipient { get; set; } | ||
#endif | ||
|
||
/// <summary> | ||
/// ID for the asynchronous response, will be generated if not set. Currently this field is not used for idempotency. | ||
/// </summary> | ||
public string RequestId { get; set; } | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/Sinch/Conversation/Capability/LookupCapabilityResponse.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using Sinch.Conversation.Common; | ||
|
||
namespace Sinch.Conversation.Capability | ||
{ | ||
public class LookupCapabilityResponse | ||
{ | ||
/// <summary> | ||
/// The ID of the app to use for capability lookup. | ||
/// </summary> | ||
#if NET7_0_OR_GREATER | ||
public required string AppId { get; set; } | ||
#else | ||
public string AppId { get; set; } | ||
#endif | ||
|
||
/// <summary> | ||
/// The recipient to lookup capabilities for. Requires either contact_id or identified_by. | ||
/// </summary> | ||
#if NET7_0_OR_GREATER | ||
public required IRecipient Recipient { get; set; } | ||
#else | ||
public IRecipient Recipient { get; set; } | ||
#endif | ||
|
||
/// <summary> | ||
/// ID for the asynchronous response, will be generated if not set. Currently this field is not used for idempotency. | ||
/// </summary> | ||
public string RequestId { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using Sinch.Conversation.Events.AppEvents; | ||
|
||
namespace Sinch.Conversation.Common | ||
{ | ||
/// <summary> | ||
/// Represents an agent that is involved in a conversation. | ||
/// </summary> | ||
public class Agent | ||
{ | ||
/// <summary> | ||
/// Agent's display name | ||
/// </summary> | ||
public string DisplayName { get; set; } | ||
|
||
public AgentType Type { get; set; } | ||
|
||
/// <summary> | ||
/// The Agent's picture url. | ||
/// </summary> | ||
public string PictureUrl { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.Text.Json.Serialization; | ||
using Sinch.Core; | ||
|
||
namespace Sinch.Conversation.Common | ||
{ | ||
[JsonConverter(typeof(EnumRecordJsonConverter<AgentType>))] | ||
public record AgentType(string Value) : EnumRecord(Value) | ||
{ | ||
/// <summary> | ||
/// The default AgentType. When the agent type is unknown. | ||
/// </summary> | ||
public static readonly AgentType UnknownAgentType = new("UNKNOWN_AGENT_TYPE"); | ||
|
||
/// <summary> | ||
/// Human agent. | ||
/// </summary> | ||
public static readonly AgentType Human = new("HUMAN"); | ||
|
||
/// <summary> | ||
/// Bot agent. | ||
/// </summary> | ||
public static readonly AgentType Bot = new("BOT"); | ||
} | ||
} |
14 changes: 1 addition & 13 deletions
14
...Sinch/Conversation/Messages/Identified.cs → ...ch/Conversation/Common/ChannelIdentity.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/Sinch/Conversation/Messages/ContactId.cs → src/Sinch/Conversation/Common/ContactId.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using Sinch.Core; | ||
|
||
namespace Sinch.Conversation.Common | ||
{ | ||
[JsonInterfaceConverter(typeof(InterfaceConverter<IRecipient>))] | ||
public interface IRecipient | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System.Collections.Generic; | ||
using Sinch.Conversation.Messages; | ||
|
||
namespace Sinch.Conversation.Common | ||
{ | ||
public class Identified : IRecipient | ||
{ | ||
public IdentifiedBy IdentifiedBy { get; set; } | ||
} | ||
|
||
public class IdentifiedBy | ||
{ | ||
public List<ChannelIdentity> ChannelIdentities { get; set; } | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...Sinch/Conversation/Apps/ProcessingMode.cs → ...nch/Conversation/Common/ProcessingMode.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
src/Sinch/Conversation/Contacts/GetChannelProfile/GetChannelProfileRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.