Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guitarrapc/421df29eef9f30ef2f566f807e462377 to your computer and use it in GitHub Desktop.
Save guitarrapc/421df29eef9f30ef2f566f807e462377 to your computer and use it in GitHub Desktop.
#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