/// <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); } }
/// <summary> /// Process Inbound Request from the Line Channel /// </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) { throw new ArgumentNullException(nameof(content)); } if (request == null) { throw new ArgumentNullException(nameof(request)); } var events = _lineClient.GetWebhookEvents(request, content); foreach (var eventData in events) { var eventInfo = (MessageEvent)eventData; if (eventInfo?.Type != WebhookEventType.Message) { continue; } var userProfile = await _lineClient.GetUserProfileAsync(eventInfo.Source?.UserId).ConfigureAwait(false); var activity = LineHelper.PayloadToActivity(eventInfo, userProfile); await _relayProcessor.PostActivityAsync(activity, LineActivitiesReceived).ConfigureAwait(false); } }