Skip to content

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

Closed
@ibrahim-ar

Description

@ibrahim-ar

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;
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions