Exemplo n.º 1
0
        /// <summary>
        /// Process Inbound Request from the MessageBird
        /// </summary>
        /// <param name="content">Inbound message content</param>
        /// <param name="request">Represents the incoming side of an individual HTTP request</param>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
        public async Task ProcessInboundActivitiesAsync(JToken content, HttpRequest request)
        {
            if (content == null || content.Type == JTokenType.Null)
            {
                throw new ArgumentNullException(nameof(content));
            }

            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            var jsonData = JsonConvert.SerializeObject(content);

            if (!_messageBirdClient.ValidateMessageBirdRequest(jsonData, request))
            {
                throw new InvalidOperationException(Constant.InvalidSignatureExceptionMessage);
            }

            var messagePayload = JsonConvert.DeserializeObject <MessageBirdRequestModel>(jsonData);
            var activity       = MessageBirdHelper.PayloadToActivity(messagePayload);

            if (activity != null)
            {
                await _relayProcessor.PostActivityAsync(activity, MessageBirdActivitiesReceived).ConfigureAwait(false);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Accept outbound Activities from Message Relay Processor, convert it into channel response model
        /// and send it to Message Bird Channel Messaging API
        /// </summary>
        /// <param name="outboundActivities">The outbound activities</param>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
        public async Task ProcessOutboundActivitiesAsync(IList <Activity> outboundActivities)
        {
            if (outboundActivities == null || outboundActivities.Count == 0)
            {
                throw new ArgumentNullException(nameof(outboundActivities));
            }

            var replyToId            = outboundActivities[0]?.ReplyToId;
            var messageBirdResponses = MessageBirdHelper.ActivityToMessageBird(outboundActivities, replyToId);
            await _messageBirdClient.SendMessagesToMessageBird(messageBirdResponses).ConfigureAwait(false);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Check if request is sent from MessageBird
 /// </summary>
 /// <param name="content">Request Content</param>
 /// <param name="request">HTTP Request</param>
 /// <returns>status of the Request Validation</returns>
 public bool ValidateMessageBirdRequest(string content, HttpRequest request)
 {
     return(MessageBirdHelper.ValidateMessageBirdRequest(
                content, request,
                _messageBirdAdapterConfiguration.Value.MessageBirdSigningKey));
 }