/// <summary> /// A simple function that takes a string and does a ToUpper /// </summary> /// <param name="input"></param> /// <param name="context"></param> /// <returns></returns> public async Task <int> FunctionHandler(ChatworkInput input, ILambdaContext context) { context.Logger.LogLine($"{nameof(SendToChatwork)} was triggered"); if (input.Channel == 0) { throw new ArgumentOutOfRangeException(nameof(input.Channel)); } if (string.IsNullOrWhiteSpace(input.Text)) { throw new ArgumentOutOfRangeException(nameof(input.Text)); } if (string.IsNullOrWhiteSpace(chatworkApiKey)) { throw new NullReferenceException(nameof(chatworkApiKey)); } var roomId = input.Channel; var body = input.Text; var client = new ChatworkClient(chatworkApiKey); var response = await client.Room.SendMessgesAsync(roomId, body); return(response.message_id); }
public static void Main(string[] args) { var input = new ChatworkInput { Channel = int.Parse(Environment.GetEnvironmentVariable("ChatworkChannel")), Text = "Send from AWS Lambda" }; // Local Async Execution will fail with NullReference Exception when using Logger. var responseTask = new Function().FunctionHandler(input, new LambdaContext()); var response = responseTask.Result; Console.WriteLine(response); }