Пример #1
0
        /// <summary>
        /// Asynchronously sends the specified message.
        /// </summary>
        /// <param name="message">The message to send.</param>
        /// <param name="cancellationToken">A token to monitor for cancellation requests. The default value is <see cref="System.Threading.CancellationToken.None"/>.</param>
        /// <returns>The message.</returns>
        public async Task SendAsync(Message message, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (message == null) throw new ArgumentNullException("message");
            if (_isDisposed) throw new ObjectDisposedException("Client");
            if (ConnectionState != ClientConnectionState.Established) throw new InvalidOperationException("Client must be connected.");

            var json = message.ToJson();
            var response = await Http.PostJsonAsync("https://slack.com/api/chat.postMessage", json, cancellationToken, "token", _token);
            if (response["ok"] != "true")
                throw SlackException.FromStatusCode(response["error"]);
        }