// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschraenkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using System.ComponentModel.DataAnnotations;
using CoreTweet;
using Microsoft.Extensions.Options;
using Squidex.Domain.Apps.Core.Rules.Deprecated;
using Squidex.Flows;
using Squidex.Infrastructure.Reflection;
using Squidex.Infrastructure.Validation;
namespace Squidex.Extensions.Actions.Twitter;
[FlowStep(
Title = "Twitter",
IconImage = "",
IconColor = "#1da1f2",
Display = "Tweet",
Description = "Tweet an update with your twitter account.",
ReadMore = "https://twitter.com")]
#pragma warning disable CS0618 // Type or member is obsolete
public sealed record TweetFlowStep : FlowStep, IConvertibleToAction
#pragma warning restore CS0618 // Type or member is obsolete
{
[LocalizedRequired]
[Display(Name = "Access Token", Description = " The generated access token.")]
[Editor(FlowStepEditor.Text)]
public string AccessToken { get; set; }
[LocalizedRequired]
[Display(Name = "Access Secret", Description = " The generated access secret.")]
[Editor(FlowStepEditor.Text)]
public string AccessSecret { get; set; }
[LocalizedRequired]
[Display(Name = "Text", Description = "The text that is sent as tweet to twitter.")]
[Editor(FlowStepEditor.TextArea)]
[Expression]
public string Text { get; set; }
public override async ValueTask ExecuteAsync(FlowExecutionContext executionContext,
CancellationToken ct)
{
if (executionContext.IsSimulation)
{
executionContext.LogSkipSimulation();
return Next();
}
var twitterOptions = executionContext.Resolve>().Value;
var tokens = Tokens.Create(
twitterOptions.ClientId,
twitterOptions.ClientSecret,
AccessToken,
AccessSecret);
var request = new Dictionary
{
["status"] = Text,
};
await tokens.Statuses.UpdateAsync(request, ct);
executionContext.Log("Tweeted", Text);
return Next();
}
#pragma warning disable CS0618 // Type or member is obsolete
public RuleAction ToAction()
{
return SimpleMapper.Map(this, new TweetAction());
}
#pragma warning restore CS0618 // Type or member is obsolete
}