/// <summary> /// Marks a welcome message as the default. /// </summary> /// <param name="welcomeMessageID">ID of the welcome message.</param> /// <param name="cancelToken">Async cancellation token.</param> /// <returns>Direct message events data.</returns> public async Task <WelcomeMessage> NewWelcomeMessageRuleAsync(ulong welcomeMessageID, CancellationToken cancelToken = default(CancellationToken)) { if (welcomeMessageID == 0) { throw new ArgumentException($"{nameof(welcomeMessageID)} is a required parameter, but it's value is 0, which is invalid.", nameof(welcomeMessageID)); } var newUrl = BaseUrl + "direct_messages/welcome_messages/rules/new.json"; var msgParams = new WelcomeMessageValue { WelcomeMessageRule = new WelcomeMessageRule { WelcomeMessageID = welcomeMessageID.ToString() } }; RawResult = await TwitterExecutor.SendJsonToTwitterAsync( HttpMethod.Post.ToString(), newUrl, new Dictionary <string, string>(), msgParams, cancelToken) .ConfigureAwait(false); var reqProc = new WelcomeMessageRequestProcessor <WelcomeMessage>(); WelcomeMessage msg = reqProc.ProcessActionResult(RawResult, WelcomeMessageType.ShowMessage); msg.ID = welcomeMessageID; return(msg); }
IEnumerable <WelcomeMessage> HandleWelcomeMessage(string msgJson) { WelcomeMessageValue welcomeMsg = JsonConvert.DeserializeObject <WelcomeMessageValue>(msgJson); return(new List <WelcomeMessage> { new WelcomeMessage { Type = Type, Count = Count, Cursor = Cursor, ID = ID, Value = welcomeMsg } }); }
/// <summary> /// Creates a new welcome message. /// </summary> /// <param name="name">Name of welcome message.</param> /// <param name="text">Welcome message contents.</param> /// <param name="cancelToken">Async cancellation token.</param> /// <returns>Direct message events data.</returns> public async Task <WelcomeMessage?> NewWelcomeMessageAsync(string name, string text, CancellationToken cancelToken = default(CancellationToken)) { if (string.IsNullOrWhiteSpace(text)) { throw new ArgumentException($"{nameof(text)} is a required parameter.", nameof(text)); } var newUrl = BaseUrl + "direct_messages/welcome_messages/new.json"; var msgParams = new WelcomeMessageValue { WelcomeMessage = new WelcomeMsg { Name = name, MessageData = new WelcomeMessageData { Text = text } }, Apps = JsonDocument.Parse("null").RootElement }; RawResult = await TwitterExecutor.SendJsonToTwitterAsync( HttpMethod.Post.ToString(), newUrl, new Dictionary <string, string>(), msgParams, cancelToken) .ConfigureAwait(false); var reqProc = new WelcomeMessageRequestProcessor <WelcomeMessage>(); WelcomeMessage?msg = reqProc.ProcessActionResult(RawResult, WelcomeMessageType.ShowMessage); //msg.Name = name; //msg.Text = text; return(msg); }