【发布时间】:2019-04-08 20:13:42
【问题描述】:
我有一个 azure 函数设置为从事件中心读取数据,以通过 sendgrid 或 twilio 发送警报消息。当我发送 SendGrid 消息“await smsCollector.AddAsync(mobileMessage)”时,我希望能够知道它是否发送成功——即电子邮件不是无效的。这个设置可以吗?
public static class SendAlert
{
[FunctionName("v1_EventHub_SendAlert")]
public static async Task Run(
[EventHubTrigger("v1-email-hub", Connection = "EventHubConnection")] EventData[] events,
[SendGrid] IAsyncCollector<SendGridMessage> messageCollector,
[TwilioSms(From = "xXXXxxXxxx)] IAsyncCollector<CreateMessageOptions> smsCollector,
[Inject] NotificationEventLogic eventLogic,
[Inject] NotificationLogic notificationLogic,
ILogger log)
{
foreach (EventData eventData in events)
{
string messageBody = Encoding.UTF8.GetString(eventData.Body.Array, eventData.Body.Offset, eventData.Body.Count);
var notificationEvents = JsonConvert.DeserializeObject<List<NotificationEvent>>(messageBody);
foreach (var ev in notificationEvents)
{
var notification = await notificationLogic.GetNotificationAsync(ev.NotificationId);
if (ev.NotificationEventType == NotificationEventType.Email)
{
var message = CreateEmail(ev, notification);
await messageCollector.AddAsync(message);
}
else if (ev.NotificationEventType == NotificationEventType.SMS)
{
var mobileMessage = CreateSms(ev, notification);
await smsCollector.AddAsync(mobileMessage);
}
await eventLogic.CreateEventAsync(ev);
}
}
}
【问题讨论】:
标签: twilio azure-functions sendgrid azure-eventhub