Twilio API - How to hang up all active calls using C#?












0















I'm looking for help in hanging up all calls regardless of status, using C# and the Twilio API. Something like a no nonsense 'Kill Switch'.



I saw this code written in python and wondered if anyone had any examples in C# I could look at?



from twilio.rest import TwilioRestClient
from twilio.rest.resources import Call

ACCOUNT_SID = "YOUR_ACCOUNT_SID"
AUTH_TOKEN = "YOUR_AUTH_TOKEN"
client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)
calls = client.calls.list(status=Call.IN_PROGRESS)

for c in calls:
c.hangup()









share|improve this question



























    0















    I'm looking for help in hanging up all calls regardless of status, using C# and the Twilio API. Something like a no nonsense 'Kill Switch'.



    I saw this code written in python and wondered if anyone had any examples in C# I could look at?



    from twilio.rest import TwilioRestClient
    from twilio.rest.resources import Call

    ACCOUNT_SID = "YOUR_ACCOUNT_SID"
    AUTH_TOKEN = "YOUR_AUTH_TOKEN"
    client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)
    calls = client.calls.list(status=Call.IN_PROGRESS)

    for c in calls:
    c.hangup()









    share|improve this question

























      0












      0








      0








      I'm looking for help in hanging up all calls regardless of status, using C# and the Twilio API. Something like a no nonsense 'Kill Switch'.



      I saw this code written in python and wondered if anyone had any examples in C# I could look at?



      from twilio.rest import TwilioRestClient
      from twilio.rest.resources import Call

      ACCOUNT_SID = "YOUR_ACCOUNT_SID"
      AUTH_TOKEN = "YOUR_AUTH_TOKEN"
      client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)
      calls = client.calls.list(status=Call.IN_PROGRESS)

      for c in calls:
      c.hangup()









      share|improve this question














      I'm looking for help in hanging up all calls regardless of status, using C# and the Twilio API. Something like a no nonsense 'Kill Switch'.



      I saw this code written in python and wondered if anyone had any examples in C# I could look at?



      from twilio.rest import TwilioRestClient
      from twilio.rest.resources import Call

      ACCOUNT_SID = "YOUR_ACCOUNT_SID"
      AUTH_TOKEN = "YOUR_AUTH_TOKEN"
      client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)
      calls = client.calls.list(status=Call.IN_PROGRESS)

      for c in calls:
      c.hangup()






      c# .net twilio twilio-api






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 14 '18 at 20:37









      JamesJames

      63




      63
























          2 Answers
          2






          active

          oldest

          votes


















          2














          You can do something like this:



          // Install the C# / .NET helper library from twilio.com/docs/csharp/install

          using System;
          using Twilio;
          using Twilio.Rest.Api.V2010.Account;


          class Program
          {
          static void Main(string args)
          {
          // Find your Account Sid and Token at twilio.com/console
          const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
          const string authToken = "your_auth_token";

          TwilioClient.Init(accountSid, authToken);

          var call = CallResource.Update(
          status: CallResource.UpdateStatusEnum.Completed,
          pathSid: "CAe1644a7eed5088b159577c5802d8be38"
          );

          Console.WriteLine(call.To);
          }
          }


          You can wrap the CallResource.Update(...) method in a for loop and pass a list of active calls as a parameter.



          You can find more information here: https://www.twilio.com/docs/voice/tutorials/how-to-modify-calls-in-progress-in-csharp#hanging-up-a-call-in-progress






          share|improve this answer
























          • Thanks Tim. Yes, I had the API reference guide up. I noted though, that in some cases, other languages like python seem to have more available options than C#. It led me to wonder if there was a C# equivalent of the .hangup call. I'm new to C# (like this week) and I don't have a great deal of experience in coding anyway.

            – James
            Nov 15 '18 at 9:13





















          0














          I came up with this. Not elegant in the least, but it works:



          private void KillSwitch(string accountSid, string authToken)
          {
          TwilioClient.Init(accountSid, authToken);
          var callsInProgress = CallResource.Read(status: CallResource.StatusEnum.InProgress);
          var callsQueued = CallResource.Read(status: CallResource.StatusEnum.Queued);
          var callsRinging = CallResource.Read(status: CallResource.StatusEnum.Ringing);
          foreach (var call in callsQueued)
          {
          CallResource.Update(status: CallResource.UpdateStatusEnum.Completed, pathSid: call.Sid);
          }
          foreach (var call in callsInProgress)
          {
          CallResource.Update(status: CallResource.UpdateStatusEnum.Completed, pathSid: call.Sid);
          }
          foreach (var call in callsRinging)
          {
          CallResource.Update(status: CallResource.UpdateStatusEnum.Completed, pathSid: call.Sid);
          }
          }





          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53308368%2ftwilio-api-how-to-hang-up-all-active-calls-using-c%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2














            You can do something like this:



            // Install the C# / .NET helper library from twilio.com/docs/csharp/install

            using System;
            using Twilio;
            using Twilio.Rest.Api.V2010.Account;


            class Program
            {
            static void Main(string args)
            {
            // Find your Account Sid and Token at twilio.com/console
            const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
            const string authToken = "your_auth_token";

            TwilioClient.Init(accountSid, authToken);

            var call = CallResource.Update(
            status: CallResource.UpdateStatusEnum.Completed,
            pathSid: "CAe1644a7eed5088b159577c5802d8be38"
            );

            Console.WriteLine(call.To);
            }
            }


            You can wrap the CallResource.Update(...) method in a for loop and pass a list of active calls as a parameter.



            You can find more information here: https://www.twilio.com/docs/voice/tutorials/how-to-modify-calls-in-progress-in-csharp#hanging-up-a-call-in-progress






            share|improve this answer
























            • Thanks Tim. Yes, I had the API reference guide up. I noted though, that in some cases, other languages like python seem to have more available options than C#. It led me to wonder if there was a C# equivalent of the .hangup call. I'm new to C# (like this week) and I don't have a great deal of experience in coding anyway.

              – James
              Nov 15 '18 at 9:13


















            2














            You can do something like this:



            // Install the C# / .NET helper library from twilio.com/docs/csharp/install

            using System;
            using Twilio;
            using Twilio.Rest.Api.V2010.Account;


            class Program
            {
            static void Main(string args)
            {
            // Find your Account Sid and Token at twilio.com/console
            const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
            const string authToken = "your_auth_token";

            TwilioClient.Init(accountSid, authToken);

            var call = CallResource.Update(
            status: CallResource.UpdateStatusEnum.Completed,
            pathSid: "CAe1644a7eed5088b159577c5802d8be38"
            );

            Console.WriteLine(call.To);
            }
            }


            You can wrap the CallResource.Update(...) method in a for loop and pass a list of active calls as a parameter.



            You can find more information here: https://www.twilio.com/docs/voice/tutorials/how-to-modify-calls-in-progress-in-csharp#hanging-up-a-call-in-progress






            share|improve this answer
























            • Thanks Tim. Yes, I had the API reference guide up. I noted though, that in some cases, other languages like python seem to have more available options than C#. It led me to wonder if there was a C# equivalent of the .hangup call. I'm new to C# (like this week) and I don't have a great deal of experience in coding anyway.

              – James
              Nov 15 '18 at 9:13
















            2












            2








            2







            You can do something like this:



            // Install the C# / .NET helper library from twilio.com/docs/csharp/install

            using System;
            using Twilio;
            using Twilio.Rest.Api.V2010.Account;


            class Program
            {
            static void Main(string args)
            {
            // Find your Account Sid and Token at twilio.com/console
            const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
            const string authToken = "your_auth_token";

            TwilioClient.Init(accountSid, authToken);

            var call = CallResource.Update(
            status: CallResource.UpdateStatusEnum.Completed,
            pathSid: "CAe1644a7eed5088b159577c5802d8be38"
            );

            Console.WriteLine(call.To);
            }
            }


            You can wrap the CallResource.Update(...) method in a for loop and pass a list of active calls as a parameter.



            You can find more information here: https://www.twilio.com/docs/voice/tutorials/how-to-modify-calls-in-progress-in-csharp#hanging-up-a-call-in-progress






            share|improve this answer













            You can do something like this:



            // Install the C# / .NET helper library from twilio.com/docs/csharp/install

            using System;
            using Twilio;
            using Twilio.Rest.Api.V2010.Account;


            class Program
            {
            static void Main(string args)
            {
            // Find your Account Sid and Token at twilio.com/console
            const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
            const string authToken = "your_auth_token";

            TwilioClient.Init(accountSid, authToken);

            var call = CallResource.Update(
            status: CallResource.UpdateStatusEnum.Completed,
            pathSid: "CAe1644a7eed5088b159577c5802d8be38"
            );

            Console.WriteLine(call.To);
            }
            }


            You can wrap the CallResource.Update(...) method in a for loop and pass a list of active calls as a parameter.



            You can find more information here: https://www.twilio.com/docs/voice/tutorials/how-to-modify-calls-in-progress-in-csharp#hanging-up-a-call-in-progress







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 14 '18 at 22:32









            Tim AlonsoTim Alonso

            367




            367













            • Thanks Tim. Yes, I had the API reference guide up. I noted though, that in some cases, other languages like python seem to have more available options than C#. It led me to wonder if there was a C# equivalent of the .hangup call. I'm new to C# (like this week) and I don't have a great deal of experience in coding anyway.

              – James
              Nov 15 '18 at 9:13





















            • Thanks Tim. Yes, I had the API reference guide up. I noted though, that in some cases, other languages like python seem to have more available options than C#. It led me to wonder if there was a C# equivalent of the .hangup call. I'm new to C# (like this week) and I don't have a great deal of experience in coding anyway.

              – James
              Nov 15 '18 at 9:13



















            Thanks Tim. Yes, I had the API reference guide up. I noted though, that in some cases, other languages like python seem to have more available options than C#. It led me to wonder if there was a C# equivalent of the .hangup call. I'm new to C# (like this week) and I don't have a great deal of experience in coding anyway.

            – James
            Nov 15 '18 at 9:13







            Thanks Tim. Yes, I had the API reference guide up. I noted though, that in some cases, other languages like python seem to have more available options than C#. It led me to wonder if there was a C# equivalent of the .hangup call. I'm new to C# (like this week) and I don't have a great deal of experience in coding anyway.

            – James
            Nov 15 '18 at 9:13















            0














            I came up with this. Not elegant in the least, but it works:



            private void KillSwitch(string accountSid, string authToken)
            {
            TwilioClient.Init(accountSid, authToken);
            var callsInProgress = CallResource.Read(status: CallResource.StatusEnum.InProgress);
            var callsQueued = CallResource.Read(status: CallResource.StatusEnum.Queued);
            var callsRinging = CallResource.Read(status: CallResource.StatusEnum.Ringing);
            foreach (var call in callsQueued)
            {
            CallResource.Update(status: CallResource.UpdateStatusEnum.Completed, pathSid: call.Sid);
            }
            foreach (var call in callsInProgress)
            {
            CallResource.Update(status: CallResource.UpdateStatusEnum.Completed, pathSid: call.Sid);
            }
            foreach (var call in callsRinging)
            {
            CallResource.Update(status: CallResource.UpdateStatusEnum.Completed, pathSid: call.Sid);
            }
            }





            share|improve this answer




























              0














              I came up with this. Not elegant in the least, but it works:



              private void KillSwitch(string accountSid, string authToken)
              {
              TwilioClient.Init(accountSid, authToken);
              var callsInProgress = CallResource.Read(status: CallResource.StatusEnum.InProgress);
              var callsQueued = CallResource.Read(status: CallResource.StatusEnum.Queued);
              var callsRinging = CallResource.Read(status: CallResource.StatusEnum.Ringing);
              foreach (var call in callsQueued)
              {
              CallResource.Update(status: CallResource.UpdateStatusEnum.Completed, pathSid: call.Sid);
              }
              foreach (var call in callsInProgress)
              {
              CallResource.Update(status: CallResource.UpdateStatusEnum.Completed, pathSid: call.Sid);
              }
              foreach (var call in callsRinging)
              {
              CallResource.Update(status: CallResource.UpdateStatusEnum.Completed, pathSid: call.Sid);
              }
              }





              share|improve this answer


























                0












                0








                0







                I came up with this. Not elegant in the least, but it works:



                private void KillSwitch(string accountSid, string authToken)
                {
                TwilioClient.Init(accountSid, authToken);
                var callsInProgress = CallResource.Read(status: CallResource.StatusEnum.InProgress);
                var callsQueued = CallResource.Read(status: CallResource.StatusEnum.Queued);
                var callsRinging = CallResource.Read(status: CallResource.StatusEnum.Ringing);
                foreach (var call in callsQueued)
                {
                CallResource.Update(status: CallResource.UpdateStatusEnum.Completed, pathSid: call.Sid);
                }
                foreach (var call in callsInProgress)
                {
                CallResource.Update(status: CallResource.UpdateStatusEnum.Completed, pathSid: call.Sid);
                }
                foreach (var call in callsRinging)
                {
                CallResource.Update(status: CallResource.UpdateStatusEnum.Completed, pathSid: call.Sid);
                }
                }





                share|improve this answer













                I came up with this. Not elegant in the least, but it works:



                private void KillSwitch(string accountSid, string authToken)
                {
                TwilioClient.Init(accountSid, authToken);
                var callsInProgress = CallResource.Read(status: CallResource.StatusEnum.InProgress);
                var callsQueued = CallResource.Read(status: CallResource.StatusEnum.Queued);
                var callsRinging = CallResource.Read(status: CallResource.StatusEnum.Ringing);
                foreach (var call in callsQueued)
                {
                CallResource.Update(status: CallResource.UpdateStatusEnum.Completed, pathSid: call.Sid);
                }
                foreach (var call in callsInProgress)
                {
                CallResource.Update(status: CallResource.UpdateStatusEnum.Completed, pathSid: call.Sid);
                }
                foreach (var call in callsRinging)
                {
                CallResource.Update(status: CallResource.UpdateStatusEnum.Completed, pathSid: call.Sid);
                }
                }






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 15 '18 at 9:16









                JamesJames

                63




                63






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53308368%2ftwilio-api-how-to-hang-up-all-active-calls-using-c%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Florida Star v. B. J. F.

                    Danny Elfman

                    Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues