Exemplo n.º 1
0
        public async Task GetMrvlCoLink(SlackCommandRequest slackCommandRequest)
        {
            var client        = new SbmClient(slackCommandRequest.ResponseUrl);
            var firstResponse = new Message();

            firstResponse.SetResponseType(ResponseType.Ephemeral);
            firstResponse.Text = "Sure thing! Let me get to work!";
            await client.SendAsync(firstResponse).ConfigureAwait(false);

            var message = new Message();

            message.SetResponseType(ResponseType.Ephemeral);
            message.UnfurlLinks = false;
            message.UnfurlMedia = false;

            var response = string.Empty;
            var textList = slackCommandRequest.Text.Split(" ").ToList();

            if (textList.Count() == 2)
            {
                var longUrl      = textList[0];
                var emailAddress = textList[1];

                var shortenerMessage = await _urlShorteningService.Shorten(longUrl, Constants.UrlShortenerDomains.MrvlCo, emailAddress, OriginSources.Slack, slackCommandRequest.TriggerId);

                message.Text = shortenerMessage;
                response     = await client.SendAsync(message);
            }
            else
            {
                message.Text = "Please verify that your message is in the format of URL<space>EmailAddress";
                response     = await client.SendAsync(message).ConfigureAwait(false);
            }

            if (response == "ok")
            {
                _logger.LogInformation("GetMrvlCoLink: Responded to {MessageText} and sent message {@Message}", slackCommandRequest.Text, message);
            }
            else
            {
                _logger.LogError("GetMrvlCoLink: Tried responding to {MessageText} but received an error sending {@Message}", slackCommandRequest.Text, message);
            }
        }
Exemplo n.º 2
0
        public async Task <(string, DialogFlowResponse.FulfillmentMessage, PayloadSettings)> Build(string longUrl, string domain, string emailAddress, OriginSources originSource, string sessionId)
        {
            _logger.LogInformation("ShortenUrlBuilder: Received request to shorten {LongUrl} to a {Domain} domain from {OriginSource}. SessionId: {SessionId}.", longUrl, domain, originSource, sessionId);

            #region Set Defaults
            var responseFulfillmentMessage = new DialogFlowResponse.FulfillmentMessage
            {
                Text = new DialogFlowResponse.Text()
                {
                    Texts = new[] { $"Sorry, couldn't shorten {longUrl} to a {domain} domain." }
                }
            };

            var responseFulfillmentText = $"Sorry, couldn't shorten {longUrl} to a {domain} domain.";

            var payloadBuilder = Payloads.DefaultPayload.Build(longUrl, domain);
            #endregion

            try
            {
                var shortenerMessage = await _urlShorteningService.Shorten(longUrl, domain, emailAddress, originSource, sessionId);

                responseFulfillmentText         = shortenerMessage;
                responseFulfillmentMessage.Text = new DialogFlowResponse.Text()
                {
                    Texts = new[] { responseFulfillmentText }
                };

                payloadBuilder.Google   = Payloads.GooglePayload.Build(responseFulfillmentText.RemoveLineEndings());
                payloadBuilder.Facebook = Payloads.FacebookPayload.Build(responseFulfillmentText);
            }
            catch (Exception ex)
            {
                _logger.LogError("ShortenUrlBuilder: There was an error while trying to use the UrlShorteningService. Error: {@Error}", ex);
            }

            return(responseFulfillmentText, responseFulfillmentMessage, payloadBuilder);
        }