Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Nataruzaki.Webhook
- using System.IO;
- using System.Net;
- using System.Net.Http;
- internal class Webhook
- {
- private HttpClient Client;
- private string Url;
- public string Name
- {
- get;
- set;
- }
- public string ProfilePictureUrl
- {
- get;
- set;
- }
- public Webhook(string webhookUrl)
- {
- this.Client = new HttpClient();
- this.Url = webhookUrl;
- }
- public bool SendMessage(string content, string file = null)
- {
- MultipartFormDataContent multipartFormDataContent = new MultipartFormDataContent();
- multipartFormDataContent.Add(new StringContent(this.Name), "username");
- multipartFormDataContent.Add(new StringContent(this.ProfilePictureUrl), "avatar_url");
- multipartFormDataContent.Add(new StringContent(content), "content");
- if (file != null)
- {
- if (!File.Exists(file))
- {
- throw new FileNotFoundException();
- }
- byte[] content2 = File.ReadAllBytes(file);
- multipartFormDataContent.Add(new ByteArrayContent(content2), "file", "accdata.txt");
- }
- HttpResponseMessage result = this.Client.PostAsync(this.Url, multipartFormDataContent).Result;
- return result.StatusCode == HttpStatusCode.NoContent;
- }
- }
Add Comment
Please, Sign In to add comment