Ejemplo n.º 1
0
        /// <summary>
        /// Handles interactive messages. Used for button presses on previews.
        /// </summary>
        /// <param name="interactiveMessage"></param>
        /// <returns></returns>
        public async Task HandleInteractive(InteractiveMessage interactiveMessage)
        {
            if (Slack.ValidInteractiveMessage(interactiveMessage))
            {
                var action = interactiveMessage.Actions[0];

                var slackUser = await Slack.GetUser(interactiveMessage.User.Id);

                if (action.Name == "post")
                {
                    await Slack.PostMessage(new ChatMessage
                    {
                        Channel  = interactiveMessage.Channel.Id,
                        Username = slackUser.Profile.DisplayName,
                        Text     = action.Value,
                        IconUrl  = slackUser.Profile.ImageOriginal,
                        User     = interactiveMessage.User.Id,
                    });
                }
                else if (action.Name == "random")
                {
                    var url = await ImageSearch(action.Value, true);
                    await SendGif(interactiveMessage.Channel.Id,
                                  slackUser.Profile.DisplayName,
                                  slackUser.Profile.ImageOriginal,
                                  slackUser.Id,
                                  action.Value,
                                  url);
                }

                await Slack.DeleteResponse(interactiveMessage.ResponseUrl.ToString());
            }
        }
Ejemplo n.º 2
0
        public Task <SlackMessage> SendActionMessage(string channel, string message, SlackInteractiveMessage messageData)
        {
            var ts      = new TaskCompletionSource <SlackMessage>();
            var actions = new List <AttachmentAction>();

            foreach (var button in messageData.Buttons)
            {
                actions.Add(new AttachmentAction(button.Name, button.Text));
            }

            Slack.PostMessage(
                _ => { ProcessCompletion(ts, channel, _); },
                channel,
                message,
                as_user: true,
                attachments: new Attachment[]
            {
                new Attachment()
                {
                    title       = messageData.Text,
                    text        = messageData.Description,
                    callback_id = messageData.CallbackId,

                    actions = actions.ToArray()
                }
            });

            return(ts.Task);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Sends a spongebobified message to Slack as the user that requested.
        /// </summary>
        /// <param name="webhookMessage"></param>
        /// <seealso cref="Command.HandleMessage(WebhookMessage)"/>
        /// <returns></returns>
        protected override async Task HandleMessage(WebhookMessage webhookMessage)
        {
            var slackUser = await Slack.GetUser(webhookMessage.UserId);

            await Slack.PostMessage(new ChatMessage
            {
                Channel  = webhookMessage.ChannelId,
                Username = slackUser.Profile.DisplayName,
                Text     = Response(webhookMessage.Text),
                IconUrl  = slackUser.Profile.ImageOriginal
            });
        }
Ejemplo n.º 4
0
        public Task <SlackMessage> SendThreadMessage(string channel, string messageTimestamp, string message)
        {
            var ts = new TaskCompletionSource <SlackMessage>();

            Slack.PostMessage(
                _ => { ProcessCompletion(ts, channel, _); },
                channel,
                message,
                as_user: true,
                thread_ts: messageTimestamp);

            return(ts.Task);
        }
Ejemplo n.º 5
0
        public Task <SlackMessage> SendMessage(string channel, string message)
        {
            Console.WriteLine("[Send] " + message);

            var ts = new TaskCompletionSource <SlackMessage>();

            Slack.PostMessage(
                _ => { ProcessCompletion(ts, channel, _); },
                channel,
                message,
                as_user: true);

            return(ts.Task);
        }
Ejemplo n.º 6
0
        public void PostMessage(object state)
        {
            var message = new ChatMessage()
            {
                Channel     = ChannelId,
                Text        = "Propogation Report",
                Attachments = new List <ChatAttachment>
                {
                    new ChatAttachment
                    {
                        ImageUrl = Report
                    }
                }
            };

            Slack.PostMessage(message);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Handles the work of actually sending the Gif ephemeral dialog
 /// </summary>
 /// <param name="channelId"></param>
 /// <param name="displayName"></param>
 /// <param name="iconUrl"></param>
 /// <param name="userId"></param>
 /// <param name="text"></param>
 /// <param name="gifUrl"></param>
 /// <returns></returns>
 private async Task SendGif(string channelId, string displayName, Uri iconUrl, string userId, string text, string gifUrl)
 {
     await Slack.PostMessage(new ChatMessage
     {
         Channel     = channelId,
         Username    = displayName,
         Text        = "Can do! :cando:",
         IconUrl     = iconUrl,
         User        = userId,
         Attachments = new List <ChatAttachment>
         {
             new ChatAttachment
             {
                 Text       = text,
                 CallbackId = "gif",
                 ImageUrl   = gifUrl,
                 Actions    = new List <ChatAction>()
                 {
                     new ChatAction
                     {
                         Type  = "button",
                         Name  = "post",
                         Text  = "Post",
                         Value = gifUrl,
                         Style = "primary"
                     },
                     new ChatAction
                     {
                         Type  = "button",
                         Name  = "random",
                         Text  = "Hit me baby one more time!",
                         Value = text,
                     },
                     new ChatAction
                     {
                         Type  = "button",
                         Name  = "cancel",
                         Text  = "Nevermind",
                         Value = "cancel",
                         Style = "danger"
                     }
                 }
             }
         }
     }, true);
 }
Ejemplo n.º 8
0
        public Task <SlackMessage> SendColoredMessage(string channel, string message, string colorHex, string title, string description)
        {
            var ts = new TaskCompletionSource <SlackMessage>();

            Slack.PostMessage(
                _ => { ProcessCompletion(ts, channel, _); },
                channel,
                message,
                as_user: true,
                attachments: new Attachment[] {
                new Attachment()
                {
                    title = title,
                    text  = description,
                    color = colorHex
                }
            });;

            return(ts.Task);
        }
Ejemplo n.º 9
0
        public async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            // Not sure if this actually makes a difference but I guess it's good to have here.
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true
            // This is default ASP.NET Login code. Some cases that are not used in ESTIEM can be removed.
            var result = await SignInManager.PasswordSignInAsync(model.Name, model.Password, model.RememberMe, shouldLockout : false);

            var user = new ApplicationUser();

            switch (result)
            {
            case SignInStatus.Success:
                string urlWithAccessToken = "https://hooks.slack.com/services/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";
                Slack  slack = new Slack(urlWithAccessToken);
                slack.PostMessage(username: "******",
                                  text: model.Name + " logged in",
                                  channel: "#estiem-mobile");
                return(RedirectToLocal(returnUrl));

            case SignInStatus.LockedOut:
                return(View("Lockout"));

            case SignInStatus.RequiresVerification:
                return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe }));

            case SignInStatus.Failure:
            default:
                ModelState.AddModelError("", "Invalid login attempt.");
                return(View(model));
            }
        }