Exemple #1
0
        public static async Task <bool> Notify(this VRCSharpSession session, APIUser user, NotificationType type, string message)
        {
            HttpClientHandler handler = null;
            HttpClient        client  = new HttpClient();

            if (session.UseProxies)
            {
                //Load proxies from Proxies.txt
                handler       = new HttpClientHandler();
                handler.Proxy = APIExtensions.GetRandomProxy();
                client        = new HttpClient(handler);
            }

            client.DefaultRequestHeaders.Clear();
            client.DefaultRequestHeaders.Add("Authorization", session.AuthToken);

            var payload = JsonConvert.SerializeObject(new NotificationPayload()
            {
                message = message, type = type.Convert()
            });

            var response = await client.PostAsync($"https://vrchat.com/api/1/user/{user.id}/notification?apiKey={GlobalVars.ApiKey}", new StringContent(payload, Encoding.UTF8, "application/json"));

            Console.WriteLine(payload.ToString());

            if (response.StatusCode == HttpStatusCode.OK)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }