Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In App Message Template is Rendered for Email Step while fetching workflow data #90

Open
ibrahim-ar opened this issue Jan 16, 2025 · 1 comment · May be fixed by #92
Open

In App Message Template is Rendered for Email Step while fetching workflow data #90

ibrahim-ar opened this issue Jan 16, 2025 · 1 comment · May be fixed by #92
Assignees
Milestone

Comments

@ibrahim-ar
Copy link

While getting the workflow details using the endpoint "/workflows/{id}" with response as Task<NovuResponse> is is found that the for each workflow steps for email type it should return "EmailMessageTemplate" but instead it is returning "InAppMessageTemplate".

To fix this need to change the MessageTemplateConverter class:

from

public class MessageTemplateConverter : JsonCreationConverter<IMessageTemplate>
{
    protected override IMessageTemplate Create(Type objectType, JObject jObject)
    {
        if (jObject == null)
        {
            throw new ArgumentNullException(nameof(jObject));
        }

        var typeVal = jObject.SelectToken(nameof(IMessageTemplate.Type).ToLower());
        if (typeVal is not null)
        {
            var isEnum = typeVal.ToString().TryParseEnumMember<StepTypeEnum>(out var typeEnum);
            if (isEnum)
            {
                return typeEnum switch
                {
                    StepTypeEnum.InApp => new InAppMessageTemplate(),
                    StepTypeEnum.Email => new InAppMessageTemplate(),
                    StepTypeEnum.Sms => new SmsMessageTemplate(),
                    StepTypeEnum.Chat => new ChatMessageTemplate(),
                    StepTypeEnum.Push => new PushMessageTemplate(),
                    StepTypeEnum.Digest => new DigestMessageTemplate(),
                    StepTypeEnum.Trigger => new TriggerMessageTemplate(),
                    StepTypeEnum.Delay => new DelayMessageTemplate(),
                    _ => throw new InvalidOperationException($"Unknown type {typeEnum}"),
                };
            }
        }

        return default;
    }
}

it is found that the return type for Email is StepTypeEnum.Email => new InAppMessageTemplate(),
it should be StepTypeEnum.Email => new EmailMessageTemplate(),
to :

public class MessageTemplateConverter : JsonCreationConverter<IMessageTemplate>
{
    protected override IMessageTemplate Create(Type objectType, JObject jObject)
    {
        if (jObject == null)
        {
            throw new ArgumentNullException(nameof(jObject));
        }

        // All the types have the discriminator 'type' although the actual enum is different and hence not on the interface
        var typeVal = jObject.SelectToken(nameof(IMessageTemplate.Type).ToLower());
        if (typeVal is not null)
        {
            var isEnum = typeVal.ToString().TryParseEnumMember<StepTypeEnum>(out var typeEnum);
            if (isEnum)
            {
                return typeEnum switch
                {
                    StepTypeEnum.InApp => new InAppMessageTemplate(),
                    StepTypeEnum.Email => new `EmailMessageTemplate(),
                    StepTypeEnum.Sms => new SmsMessageTemplate(),
                    StepTypeEnum.Chat => new ChatMessageTemplate(),
                    StepTypeEnum.Push => new PushMessageTemplate(),
                    StepTypeEnum.Digest => new DigestMessageTemplate(),
                    StepTypeEnum.Trigger => new TriggerMessageTemplate(),
                    StepTypeEnum.Delay => new DelayMessageTemplate(),
                    _ => throw new InvalidOperationException($"Unknown type {typeEnum}"),
                };
            }
        }

        return default;
    }
}
@toddb
Copy link
Collaborator

toddb commented Jan 16, 2025

Ouch, I will get that change out in 0.4.1.

@toddb toddb self-assigned this Feb 8, 2025
@toddb toddb added this to the 0.4.1 milestone Feb 8, 2025
toddb pushed a commit that referenced this issue Feb 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants