Text Message

Description

Message providers in FlexBase expose a unified interface (IFlexTextMessageProvider) for sending SMS and notifications across providers like Twilio, Firebase, and AWS SNS.

Your application code should depend on IFlexTextMessageProvider.

Important concepts

  • IFlexTextMessageProvider is the contract: send via SendSmsAsync(...), SendPushAsync(...), or SendAsync(...).

  • Provider bridge: generated infrastructure commonly registers IFlexTextMessageProviderBridge (which also implements IFlexTextMessageProvider) so behavior can be overridden safely.

  • Channel support is provider-specific: use SupportedChannels / SupportsChannel(...) to validate capability.

Configuration in DI

Only register the provider—Flex auto-wires generated PostBus handlers/plugins that consume the interface.

public static class OtherApplicationServicesConfig
{
	public static IServiceCollection AddOtherApplicationServices(
		this IServiceCollection services,
		IConfiguration configuration)
	{
		// Pick ONE (or register multiple with different compositions).
		services.AddFlexConsoleMessageProvider(configuration);
		// services.AddFlexTwilioMessageProvider(configuration);
		// services.AddFlexFirebaseMessageProvider(configuration);
		// services.AddFlexAwsSnsMessageProvider(configuration);
		return services;
	}
}

appsettings.json

Message provider configuration is read from FlexBase:Providers:Message:<Provider>.

Examples (template-based)

This mirrors the generated PostBus handler template shape. You do not register the handler manually.

Provider considerations

  • Validate channel support via SupportsChannel(...) before sending.

  • Keep secrets (Twilio/AuthToken, AWS keys, Firebase credentials) out of source control. ["action"] = "verify", ["userId"] = 12345 }, Metadata = new Dictionary<string, string> // Tracking metadata { ["campaign"] = "signup", ["source"] = "web" } };

    var result = await _messageProvider.SendAsync(message); }

Bulk Messaging

Slack/Teams Integration

Key Points to Consider

Best Practices

  1. Validate Recipients - Use ValidateRecipient() before sending

  2. Handle Delivery Status - Check IsSuccess and log failures

  3. Use Console in Dev - Avoid sending real messages during development

  4. Set Priorities - Use High priority for time-sensitive messages

  5. Include Expiry - Set ExpiresAt for time-sensitive content

  6. Handle Rate Limits - Implement retry logic for RATE_LIMITED errors

  7. Monitor Costs - Track Cost in results for paid providers

Validation

Error Handling

Testing Connection

Examples

Complete Notification Service

Multi-Channel Alert System

Testing

See Also

Last updated