1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- using System.Text.Json;
- using Microsoft.AspNetCore.Http;
- using SlackAPI;
- using sera_slackbot.Library;
- namespace sera_slackbot.Commands
- {
- public class InvalidBotCommand : IBotCommand, IBotInteraction
- {
- private string channelId;
- private string userId;
- private string message;
- private string missingCommand;
- public InvalidBotCommand(string missingCommand)
- {
- this.missingCommand = missingCommand;
- }
- public void ExtractValidData(JsonElement slackEvent)
- {
- this.channelId = slackEvent.GetProperty("channel").ToString();
- this.userId = slackEvent.GetProperty("user").ToString();
- }
- public bool WillTrigger(JsonElement slackEvent)
- {
- return true;
- }
- public dynamic Run(SlackClient client)
- {
- message = $"Whoops! I'm sorry, \u003C@{userId}\u003E, but something is wrong in my command list.";
- client.PostMessage(response => { }, channelId, message);
- message = $"I can't seem to find '{missingCommand}'.";
- client.PostMessage(response => { }, channelId, message);
- return new
- {
- code = StatusCodes.Status200OK,
- body = ""
- };
- }
- public dynamic Interaction(SlackClient client, JsonElement payload, string actionValue)
- {
- var channelId = payload.GetProperty("container").GetProperty("channel_id").ToString();
- var userId = payload.GetProperty("user").GetProperty("id").ToString();
- client.PostMessage(response =>
- {
- client.PostMessage(response => { }, channelId, $"I'm so sorry, \u003C@{userId}\u003E, but something is wrong with this interaction.");
- }, channelId, $"Oh no! I can't seem to find '{missingCommand}'!");
- return new
- {
- code = StatusCodes.Status405MethodNotAllowed,
- body = ""
- };
- }
- }
- }
|