public override Task ExecuteAsync(string generator, WebHookHandlerContext context) { // For more information about Slack WebHook payloads, please see // 'https://api.slack.com/outgoing-webhooks' NameValueCollection entry = context.GetDataOrDefault<NameValueCollection>(); // We can trace to see what is going on. Trace.WriteLine(entry.ToString()); // Switch over the IDs we used when configuring this WebHook switch (context.Id) { case "trigger": // Information can be returned using a SlackResponse var triggerReply = new SlackResponse("Hello trigger!"); context.Response = context.Request.CreateResponse(triggerReply); break; case "slash": // Information can be returned in a plain text response context.Response = context.Request.CreateResponse(); context.Response.Content = new StringContent("Hello slash command!"); break; } return Task.FromResult(true); }
public override Task ExecuteAsync(string generator, WebHookHandlerContext context) { // For more information about Slack WebHook payloads, please see // 'https://api.slack.com/outgoing-webhooks' NameValueCollection entry = context.GetDataOrDefault<NameValueCollection>(); // We can trace to see what is going on. Trace.WriteLine(entry.ToString()); // Switch over the IDs we used when configuring this WebHook switch (context.Id) { case "trigger": MatchCollection matches = Regex.Matches(entry["text"], pattern); var spreadsheetService = new GoogleDocService(); foreach (Match match in matches) { var insertItem = new Bill { Money = match.Groups["money"].Value, ShopName = match.Groups["shopname"].Value, Date = DateTime.ParseExact(DateTime.Today.Year + "/" + match.Groups["date"].Value, "yyyy/MM/dd", CultureInfo.InvariantCulture), UserName = match.Groups["username"].Value }; spreadsheetService.Insert(insertItem); } // Information can be returned using a SlackResponse var triggerReply = new SlackResponse( "Update Google SpreadSheet(RTBS 체크카드 사용 내역서)" + Environment.NewLine + "누적 " + spreadsheetService.GetTotalMoney() + "원"); context.Response = context.Request.CreateResponse(triggerReply); break; case "slash": // Information can be returned in a plain text response context.Response = context.Request.CreateResponse(); context.Response.Content = new StringContent("Hello slash command!"); break; } return Task.FromResult(true); }
public SlackResponseTests() { _response = new SlackResponse(Text); }
public override Task ExecuteAsync(string generator, WebHookHandlerContext context) { // For more information about Slack WebHook payloads, please see // 'https://api.slack.com/outgoing-webhooks' NameValueCollection command = context.GetDataOrDefault<NameValueCollection>(); // We can trace to see what is going on. Trace.WriteLine(command.ToString()); // Switch over the IDs we used when configuring this WebHook switch (context.Id) { case "trigger": // Parse the trigger text of the form 'action parameters'. var triggerCommand = SlackCommand.ParseActionWithValue(command["subtext"]); // Information can be returned using a SlackResponse string reply1 = string.Format( "Received trigger '{0}' with action '{1}' and value '{2}'", command["trigger_word"], triggerCommand.Key, triggerCommand.Value); var triggerReply = new SlackResponse(reply1); context.Response = context.Request.CreateResponse(triggerReply); break; case "slash": // Parse the slash text of the form 'action p1=v1; p2=v2; ...'. var slashCommand = SlackCommand.ParseActionWithParameters(command["text"]); string reply2 = string.Format( "Received slash command '{0}' with action '{1}' and value '{2}'", command["command"], slashCommand.Key, slashCommand.Value.ToString()); // Information can be returned using a SlackSlashResponse with attachments var slashReply = new SlackSlashResponse(reply2); // Slash replies can be augmented with attachments containing data, images, and more var att = new SlackAttachment("Attachment Text", "Fallback description") { Color = "#439FE0", Pretext = "Hello from ASP.NET WebHooks!", Title = "Attachment title", }; // Slash attachments can contain tabular data as well att.Fields.Add(new SlackField("Field1", "1234")); att.Fields.Add(new SlackField("Field2", "5678")); // A reply can contain multiple attachments slashReply.Attachments.Add(att); // Return slash command response context.Response = context.Request.CreateResponse(slashReply); break; } return Task.FromResult(true); }