title: Configuring Twilio SMS from Azure Functions v2
body: <p>I have some code where I'm reading messages off of an Azure Event Hub that I want to either send an email or send an SMS.</p>
  
  <p>The email is working through send grid, but I'm not sure how to configure the SMS part though.</p>
  
  <p>I think I'd want to use Twilio and here's a sample of what my code's like. The "messageCollector" works for sending Email since there's some configuration for SendGrid in the local json. How do I configure Twilio?</p>
  
  <pre><code>    [FunctionName("SendAlert")]
      public static async Task Run(
          [EventHubTrigger("v1-email-hub", Connection = "EventHubConnection")] EventData[] events,
          [SendGrid] IAsyncCollector&lt;SendGridMessage&gt; messageCollector,
          [TwilioSms] IAsyncCollector&lt;CreateMessageOptions&gt; smsCollector,
          [Inject] NotificationEventLogic eventLogic,
          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&lt;List&lt;NotificationEvent&gt;&gt;(messageBody);
  
              foreach (var ev in notificationEvents)
              {
  
  
  
                  if (ev.NotificationEventType == NotificationEventType.Email)
                  {
                      var message = new SendGridMessage();
  
                      // ... ... make message and add it
                      await messageCollector.AddAsync(message);
                  }
                  else if (ev.NotificationEventType == NotificationEventType.SMS)
                  {
                      // Not sure how to get this to work
                      var mobileMessage = new CreateMessageOptions(new PhoneNumber(ev.Data))
                      {
                          Body = $"Notification {ev.NotificationId}"
                      };
  
                      await smsCollector.AddAsync(mobileMessage);
                  }
  
  
                  // await smsCollector.AddAsync()
                  await eventLogic.CreateEventAsync(ev);
              }
  
          }
      }
  </code></pre>