Created
April 4, 2016 19:13
-
-
Save guitarrapc/421df29eef9f30ef2f566f807e462377 to your computer and use it in GitHub Desktop.
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.Verbose($"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