Пример #1
0
        protected void Init(NativeActivityContext context)
        {
            string username = AccountSid.Get(context);
            string password = AuthToken.Get(context);

            TwilioClient.Init(username, password);
        }
Пример #2
0
        protected override async Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
        {
            // Object Container: Use objectContainer.Get<T>() to retrieve objects from the scope
            var objectContainer = context.GetFromContext <IObjectContainer>(TwilioApiScope.ParentContainerPropertyTag);

            // Inputs
            var to                  = To.Get(context);
            var from                = From.Get(context);
            var body                = Body.Get(context);
            var mediaurls           = MediaUrls.Get(context);
            var accountsid          = AccountSid.Get(context);
            var messagingservicesid = MessagingServiceSid.Get(context);
            var applicationsid      = ApplicationSid.Get(context);
            var statuscallback      = StatusCallback.Get(context);
            var providefeedback     = ProvideFeedback.Get(context);
            var maxprice            = MaxPrice.Get(context);
            var validityperiod      = ValidityPeriod.Get(context);
            var smartencoded        = SmartEncoded.Get(context);

            var message = await MessageWrappers.SendMessageAsync(objectContainer.Get <ITwilioRestClient>(), from, to, body, mediaurls, maxprice, validityperiod, smartencoded, accountsid, applicationsid, messagingservicesid, providefeedback, statuscallback);

            // Outputs
            return((ctx) => {
                Message.Set(ctx, message);
            });
        }
Пример #3
0
        protected override async Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
        {
            // Object Container: Use objectContainer.Get<T>() to retrieve objects from the scope
            var objectContainer = context.GetFromContext <IObjectContainer>(TwilioApiScope.ParentContainerPropertyTag);

            // Inputs
            var accountsid = AccountSid.Get(context);

            var account = await AccountWrappers.GetAccountAsync(objectContainer.Get <ITwilioRestClient>(), accountsid);

            // Outputs
            return((ctx) => {
                Account.Set(ctx, account);
            });
        }
Пример #4
0
        protected override async Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
        {
            // Object Container: Use objectContainer.Get<T>() to retrieve objects from the scope
            var objectContainer = context.GetFromContext <IObjectContainer>(TwilioApiScope.ParentContainerPropertyTag);

            // Inputs
            var messagesid = MessageSid.Get(context);
            var accountsid = AccountSid.Get(context);
            var body       = Body.Get(context);

            var updated = await MessageWrappers.UpdateMessageAsync(objectContainer.Get <ITwilioRestClient>(), messagesid, body, accountsid);

            // Outputs
            return((ctx) => {
                Message.Set(ctx, updated);
            });
        }
Пример #5
0
        protected override async Task <Action <NativeActivityContext> > ExecuteAsync(NativeActivityContext context, CancellationToken cancellationToken)
        {
            // Inputs
            var accountsid = AccountSid.Get(context);
            var authtoken  = AuthToken.Get(context);
            var region     = Region.Get(context);
            var timeout    = Timeout.Get(context);

            _objectContainer.Add(TwilioWrappers.GetTwilioRestClient(accountsid, authtoken, region, timeout));

            return((ctx) => {
                // Schedule child activities
                if (Body != null)
                {
                    ctx.ScheduleAction <IObjectContainer>(Body, _objectContainer, OnCompleted, OnFaulted);
                }

                // Outputs
            });
        }
Пример #6
0
        protected override async Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
        {
            // Object Container: Use objectContainer.Get<T>() to retrieve objects from the scope
            var objectContainer = context.GetFromContext <IObjectContainer>(TwilioApiScope.ParentContainerPropertyTag);

            // Inputs
            var from           = From.Get(context);
            var to             = To.Get(context);
            var datesent       = DateSent.Get(context);
            var datesentbefore = DateSentBefore.Get(context);
            var datesentafter  = DateSentAfter.Get(context);
            var accountsid     = AccountSid.Get(context);
            var limit          = Limit.Get(context);

            var messages = await MessageWrappers.GetMessagesAsync(objectContainer.Get <ITwilioRestClient>(), from, to, accountsid, datesent, datesentafter, datesentbefore, limit);

            // Outputs
            return((ctx) => {
                Messages.Set(ctx, messages);
            });
        }
Пример #7
0
        protected override async Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
        {
            // Object Container: Use objectContainer.Get<T>() to retrieve objects from the scope
            var objectContainer = context.GetFromContext <IObjectContainer>(TwilioApiScope.ParentContainerPropertyTag);

            // Inputs
            var accountsid   = AccountSid.Get(context);
            var friendlyname = FriendlyName.Get(context);
            var status       = Status.Get(context);
            var twilioStatus = status == AccountStatus.Active ? AccountResource.StatusEnum.Active :
                               status == AccountStatus.Closed ? AccountResource.StatusEnum.Closed :
                               status == AccountStatus.Suspended ? AccountResource.StatusEnum.Suspended :
                               null;

            var account = await AccountWrappers.UpdateAccountAsync(objectContainer.Get <ITwilioRestClient>(), accountsid,
                                                                   friendlyname, twilioStatus);

            // Outputs
            return((ctx) => {
                Account.Set(ctx, account);
            });
        }
Пример #8
0
        protected override async Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
        {
            // Object Container: Use objectContainer.Get<T>() to retrieve objects from the scope
            var objectContainer = context.GetFromContext <IObjectContainer>(TwilioApiScope.ParentContainerPropertyTag);

            // Inputs
            var countrycode  = CountryCode;
            var accountsid   = AccountSid.Get(context);
            var areacode     = AreaCode.Get(context);
            var smsenabled   = SmsEnabled.Get(context);
            var mmsenabled   = MmsEnabled.Get(context);
            var voiceenabled = VoiceEnabled.Get(context);
            var faxenabled   = FaxEnabled.Get(context);
            var contains     = Contains.Get(context);
            var beta         = Beta.Get(context);
            var nearnumber   = NearNumber.Get(context);
            var nearlatlong  = NearLatLong.Get(context);
            var distance     = Distance.Get(context);
            var inpostalcode = InPostalCode.Get(context);
            var inregion     = InRegion.Get(context);
            var inratecenter = InRateCenter.Get(context);
            var inlata       = InLata.Get(context);
            var inlocality   = InLocality.Get(context);
            var excludealladdressrequired     = ExcludeAllAddressRequired.Get(context);
            var excludelocaladdressrequired   = ExcludeLocalAddressRequired.Get(context);
            var excludeforeignaddressrequired = ExcludeForeignAddressRequired.Get(context);
            var limit = Limit.Get(context);

            var numbers = await AvailableMobilePhoneNumbersWrappers.GetAvailableMobilePhoneNumberAsync(
                objectContainer.Get <ITwilioRestClient>(), countrycode, accountsid, areacode, smsenabled, mmsenabled,
                faxenabled, voiceenabled, beta, contains, inlata, nearlatlong, nearnumber, distance, inlocality,
                inpostalcode, inratecenter, inregion, excludealladdressrequired, excludeforeignaddressrequired,
                excludelocaladdressrequired, limit);

            // Outputs
            return((ctx) => {
                PhoneNumbers.Set(ctx, numbers);
            });
        }
Пример #9
0
        /// <summary>
        /// Generate the necessary parameters
        /// </summary>
        public List <KeyValuePair <string, string> > GetParams()
        {
            var p = new List <KeyValuePair <string, string> >();

            if (AccountSid != null)
            {
                p.Add(new KeyValuePair <string, string>("AccountSid", AccountSid.ToString()));
            }

            if (ApiVersion != null)
            {
                p.Add(new KeyValuePair <string, string>("ApiVersion", ApiVersion));
            }

            if (FriendlyName != null)
            {
                p.Add(new KeyValuePair <string, string>("FriendlyName", FriendlyName));
            }

            if (SmsApplicationSid != null)
            {
                p.Add(new KeyValuePair <string, string>("SmsApplicationSid", SmsApplicationSid.ToString()));
            }

            if (SmsFallbackMethod != null)
            {
                p.Add(new KeyValuePair <string, string>("SmsFallbackMethod", SmsFallbackMethod.ToString()));
            }

            if (SmsFallbackUrl != null)
            {
                p.Add(new KeyValuePair <string, string>("SmsFallbackUrl", SmsFallbackUrl.ToString()));
            }

            if (SmsMethod != null)
            {
                p.Add(new KeyValuePair <string, string>("SmsMethod", SmsMethod.ToString()));
            }

            if (SmsUrl != null)
            {
                p.Add(new KeyValuePair <string, string>("SmsUrl", SmsUrl.ToString()));
            }

            if (StatusCallback != null)
            {
                p.Add(new KeyValuePair <string, string>("StatusCallback", StatusCallback.ToString()));
            }

            if (StatusCallbackMethod != null)
            {
                p.Add(new KeyValuePair <string, string>("StatusCallbackMethod", StatusCallbackMethod.ToString()));
            }

            if (VoiceApplicationSid != null)
            {
                p.Add(new KeyValuePair <string, string>("VoiceApplicationSid", VoiceApplicationSid.ToString()));
            }

            if (VoiceCallerIdLookup != null)
            {
                p.Add(new KeyValuePair <string, string>("VoiceCallerIdLookup", VoiceCallerIdLookup.Value.ToString()));
            }

            if (VoiceFallbackMethod != null)
            {
                p.Add(new KeyValuePair <string, string>("VoiceFallbackMethod", VoiceFallbackMethod.ToString()));
            }

            if (VoiceFallbackUrl != null)
            {
                p.Add(new KeyValuePair <string, string>("VoiceFallbackUrl", VoiceFallbackUrl.ToString()));
            }

            if (VoiceMethod != null)
            {
                p.Add(new KeyValuePair <string, string>("VoiceMethod", VoiceMethod.ToString()));
            }

            if (VoiceUrl != null)
            {
                p.Add(new KeyValuePair <string, string>("VoiceUrl", VoiceUrl.ToString()));
            }

            if (EmergencyStatus != null)
            {
                p.Add(new KeyValuePair <string, string>("EmergencyStatus", EmergencyStatus.ToString()));
            }

            if (EmergencyAddressSid != null)
            {
                p.Add(new KeyValuePair <string, string>("EmergencyAddressSid", EmergencyAddressSid.ToString()));
            }

            if (TrunkSid != null)
            {
                p.Add(new KeyValuePair <string, string>("TrunkSid", TrunkSid.ToString()));
            }

            return(p);
        }
        /// <summary>
        /// Generate the necessary parameters
        /// </summary>
        public List <KeyValuePair <string, string> > GetParams()
        {
            var p = new List <KeyValuePair <string, string> >();

            if (PhoneNumber != null)
            {
                p.Add(new KeyValuePair <string, string>("PhoneNumber", PhoneNumber.ToString()));
            }

            if (SmsCapability != null)
            {
                p.Add(new KeyValuePair <string, string>("SmsCapability", SmsCapability.Value.ToString().ToLower()));
            }

            if (AccountSid != null)
            {
                p.Add(new KeyValuePair <string, string>("AccountSid", AccountSid.ToString()));
            }

            if (FriendlyName != null)
            {
                p.Add(new KeyValuePair <string, string>("FriendlyName", FriendlyName));
            }

            if (UniqueName != null)
            {
                p.Add(new KeyValuePair <string, string>("UniqueName", UniqueName));
            }

            if (CcEmails != null)
            {
                p.AddRange(CcEmails.Select(prop => new KeyValuePair <string, string>("CcEmails", prop)));
            }

            if (SmsUrl != null)
            {
                p.Add(new KeyValuePair <string, string>("SmsUrl", SmsUrl.AbsoluteUri.TrimEnd('/')));
            }

            if (SmsMethod != null)
            {
                p.Add(new KeyValuePair <string, string>("SmsMethod", SmsMethod.ToString()));
            }

            if (SmsFallbackUrl != null)
            {
                p.Add(new KeyValuePair <string, string>("SmsFallbackUrl", SmsFallbackUrl.AbsoluteUri.TrimEnd('/')));
            }

            if (SmsFallbackMethod != null)
            {
                p.Add(new KeyValuePair <string, string>("SmsFallbackMethod", SmsFallbackMethod.ToString()));
            }

            if (StatusCallbackUrl != null)
            {
                p.Add(new KeyValuePair <string, string>("StatusCallbackUrl", StatusCallbackUrl.AbsoluteUri.TrimEnd('/')));
            }

            if (StatusCallbackMethod != null)
            {
                p.Add(new KeyValuePair <string, string>("StatusCallbackMethod", StatusCallbackMethod.ToString()));
            }

            if (SmsApplicationSid != null)
            {
                p.Add(new KeyValuePair <string, string>("SmsApplicationSid", SmsApplicationSid.ToString()));
            }

            if (AddressSid != null)
            {
                p.Add(new KeyValuePair <string, string>("AddressSid", AddressSid.ToString()));
            }

            if (Email != null)
            {
                p.Add(new KeyValuePair <string, string>("Email", Email));
            }

            if (VerificationType != null)
            {
                p.Add(new KeyValuePair <string, string>("VerificationType", VerificationType.ToString()));
            }

            if (VerificationDocumentSid != null)
            {
                p.Add(new KeyValuePair <string, string>("VerificationDocumentSid", VerificationDocumentSid.ToString()));
            }

            return(p);
        }