示例#1
0
        public async Task ProcessQueueMessage([QueueTrigger("text-messages")] TextMessageMsg message)
        {
            var twilioClient = new TwilioRestClient(_twilioOptions.AccountSid, _twilioOptions.AuthToken);

            var request = new MessageCreator(
                _twilioOptions.AccountSid,
                new PhoneNumber(message.Recipient),
                new PhoneNumber(_twilioOptions.PhoneNumber),
                message.Content);

            var response = await request.ExecuteAsync(twilioClient);

            var errorCode = response.GetErrorCode();

            if (errorCode != null)
            {
                // log error, throw exception
                // will be requeued, ensure that errorCode means wasn't sent
                throw new Exception("Error sending Twilio message");
            }
        }