コード例 #1
0
        public async Task Listen()
        {
            while (!_cancellationToken.IsCancellationRequested)
            {
                var message = await ReceiveAsync();

                OnJsonMessage?.Invoke(message);
                if (TryDeserialize <WebSocketResponse>(message, out var response))
                {
                    var channelDisplayName = response.GetDataOrDefault("channel_display_name");
                    OnWebSocketResponse?.Invoke(response);
                    if (response.TryGetData("posted", "post", out var postJson))
                    {
                        if (TryDeserialize <Posted>(postJson, out var posted))
                        {
                            OnPosted?.Invoke(new PostedEvent {
                                ChannelDisplayName = channelDisplayName,
                                Post = posted
                            });
                        }
                    }
                    if (response.TryGetData("hello", "server_version", out var serverVersion))
                    {
                        OnHello?.Invoke(serverVersion);
                        if (response.Broadcast != null && response.Broadcast.ContainsKey("user_id"))
                        {
                            OnBotUserId?.Invoke(response.Broadcast["user_id"]);
                        }
                    }
                }
            }
        }
コード例 #2
0
ファイル: SlackAPI.cs プロジェクト: otya128/RakudaSlack
 public void Post()
 {
     if (PostedMessage == null)
     {
         var col = HttpUtility.ParseQueryString(string.Empty);
         col["token"] = Slack.Token;
         Construct(col);
         var wc = new WebClient();
         PostedMessage = JsonConvert.DeserializeObject <PostedMessage>(wc.DownloadString("https://slack.com/api/chat.postMessage?" + col.ToQString()));
         OnPosted?.Invoke();
     }
     else
     {
         var col = HttpUtility.ParseQueryString(string.Empty);
         col["token"] = Slack.Token;
         col["ts"]    = PostedMessage.ts;
         Construct(col);
         var wc = new WebClient();
         JsonConvert.DeserializeObject <PostedMessage>(wc.DownloadString("https://slack.com/api/chat.update?" + col.ToQString()));
     }
 }
コード例 #3
0
 public virtual void NotifyStateChanged() => OnPosted?.Invoke(this, EventArgs.Empty);