コード例 #1
0
        public async Task <SlackSlashResponse> GenerateSlackWebHookResponse(SlackSlashCommandUserInput input)
        {
            if (string.IsNullOrEmpty(input.Phrase))
            {
                return(CreatePrivateResponse("Tomme ord, tomme løfter, hæh?! Prøv igjen."));
            }

            try
            {
                var response = await _service.GetOrdbokResponse(input.Phrase);

                if (response.Artikler.Any())
                {
                    return(CreatePublicResponse(response, input));
                }
                return(CreatePrivateResponse($"Fant ikke '{input.Phrase}' :/"));
            }
            catch (NonSuccessfulHttpQueryAgainstUiBException e)
            {
                Trace.TraceError(e.ToString());
                return(CreatePrivateResponse("Ser ikke ut som vi klarte å kalle Bergen idag. Prøv igjen senere. :/"));
            }
        }
コード例 #2
0
        private SlackSlashResponse CreatePublicResponse(OrdbokResponse ordbokResponse, SlackSlashCommandUserInput input)
        {
            var slashReply = new SlackSlashResponse("");

            foreach (var response in ordbokResponse.Artikler)
            {
                var att = CreateAtt(response);
                slashReply.Attachments.Add(att);
            }

            slashReply.ResponseType = "in_channel";
            //<http://www.foo.com|www.foo.com>
            slashReply.Text = $"'<{ordbokResponse.Link}|{input.Phrase}>' (via {input.Username}). ";
            return(slashReply);
        }