public async Task <bool> SendExtensionPubsubMessageAsync(ExtensionPubsubMessage message) { try { var request = new HttpRequestMessage(HttpMethod.Post, $"message/{message.ChannelId}"); var perms = new Dictionary <string, string[]> { { "send", new[] { "*" } } }; var token = _jwtService.CreateExternalTwitchExtensionJwt(message.ChannelId, perms); request.Headers.Add("Client-ID", _configuration["Twitch:ExtensionId"]); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token); request.Content = new StringContent(JsonSerializer.Serialize(new { ContentType = "application/json", Message = JsonSerializer.Serialize(message.Message), message.Targets })); var response = await _httpClient.SendAsync(request); response.EnsureSuccessStatusCode(); return(response.StatusCode == HttpStatusCode.NoContent); } catch { return(false); } }
public ActionResult EnqueuePubsubBroadcastMessage([FromBody] ExtensionPubsubMessage message) { if (_extensionPubsubService.EnqueuePubsubMessage(message)) { return(Ok(message)); } return(StatusCode(500)); }
public bool EnqueuePubsubMessage(ExtensionPubsubMessage message) { if (!_queues.ContainsKey(message.ChannelId)) { if (!_queues.TryAdd(message.ChannelId, new ConcurrentQueue <ExtensionPubsubMessage>())) { return(false); } } if (!_queues.TryGetValue(message.ChannelId, out var queue)) { return(false); } queue.Enqueue(message); return(true); }