Exemple #1
0
        public async Task <DialogTurnResult> SendTextAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var phone = PhoneNumbers.ContainsKey((stepContext.Result as FoundChoice)?.Value) ? PhoneNumbers[(stepContext.Result as FoundChoice)?.Value] : "6101234567";

            try
            {
                string accountSID = "AC039559141884d03c96a0f57f91357332";
                string authToken  = "1e15e552340d63875be0aecb475867b7";

                // Initialize the TwilioClient.
                TwilioClient.Init(accountSID, authToken);

                // Send message via Twilio
                var message = MessageResource.Create(
                    to: new PhoneNumber($"+1{phone}"),
                    from: new PhoneNumber("+12674777516"),
                    body: $"{PplLocations[LocationEntity]}");
            }
            catch (TwilioException ex)
            {
                await stepContext.Context.SendActivityAsync(MessageFactory.Text($"Sorry, I unable to send the location to {phone}."));

                LocationEntity = null;
                return(await stepContext.ReplaceDialogAsync(RootWaterfallDialog.DialogId, null, cancellationToken));
            }

            await stepContext.Context.SendActivityAsync(MessageFactory.Text($"I have successfully sent the location to {phone}."));

            LocationEntity = null;
            return(await stepContext.ReplaceDialogAsync(RootWaterfallDialog.DialogId, null, cancellationToken));
        }