Created
December 20, 2016 17:58
-
-
Save guitarrapc/349e662a879bd3fe33bf4fe3ef366742 to your computer and use it in GitHub Desktop.
AzureFunctions WebhookCSharpSendToChatWork sample https://github.com/guitarrapc/AzureFunctionsIntroduction/blob/master/WebhookCSharpSendToChatWork/run.csx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#r "Newtonsoft.Json" | |
#r "System.Threading.Tasks" | |
using System; | |
using System.Linq; | |
using System.Net; | |
using System.Net.Http; | |
using System.Threading.Tasks; | |
using Newtonsoft.Json; | |
using System.Reflection; | |
using Chatwork.Service; | |
public static async Task<object> Run(HttpRequestMessage req, TraceWriter log) | |
{ | |
log.Info($"Webhook was triggered!"); | |
string jsonContent = await req.Content.ReadAsStringAsync(); | |
dynamic data = JsonConvert.DeserializeObject(jsonContent); | |
if (data.channel == 0 || data.text == null) { | |
return req.CreateResponse(HttpStatusCode.BadRequest, new { | |
error = "Please pass channel/text properties in the input object" | |
}); | |
} | |
var chatworkApiKey = "INPUT YOUR API KEY HERE"; | |
int roomId = data.channel; | |
string body = data.text; | |
var client = new ChatworkClient(chatworkApiKey); | |
await client.Room.SendMessgesAsync(roomId, body); | |
return req.CreateResponse(HttpStatusCode.OK, new { | |
RoomId = roomId, | |
Message = body, | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment