public async Task <ActionResult> Phone(string number)
        {
            var util = PhoneNumbers.PhoneNumberUtil.GetInstance();
            var tmp  = util.Parse(number, "US");

            number = util.Format(tmp, PhoneNumbers.PhoneNumberFormat.E164).ToString();

            IMobileServiceTable <PhoneNumber> phoneNumberTable = MobileService.GetTable <PhoneNumber>();
            var phoneNumbers = await phoneNumberTable.ReadAsync <PhoneNumber>(phoneNumberTable.Where(p => p.Value == number));

            PhoneNumber phoneNumber = phoneNumbers.FirstOrDefault();

            if (phoneNumber == null)
            {
                //save the number and generate a new id
                phoneNumber       = new PhoneNumber();
                phoneNumber.Value = number;
                await phoneNumberTable.InsertAsync(phoneNumber);
            }

            var capability = new TwilioCapability(Credentials.AccountSid, Credentials.AuthToken);

            capability.AllowClientIncoming(phoneNumber.Key.ToString("N"));
            capability.AllowClientOutgoing("AP08b4c661205ac48c6e896a83fc12aec1");
            var token = capability.GenerateToken();

            ViewBag.token  = token;
            ViewBag.source = number;

            return(View());
        }
Esempio n. 2
0
        public string GetToken(Agent agent, int seconds = 60 *60 *24)
        {
            var twilioCapability = new TwilioCapability(accountSid, authToken);

            twilioCapability.AllowClientIncoming(agent.ClientID);
            return(twilioCapability.GenerateToken(seconds));
        }
Esempio n. 3
0
        public string GetToken(string clientId)
        {
            var capability = new TwilioCapability(AccountSid, AuthToken);

            /*
             * A device configured with this token will receive incoming connections
             * anytime someone attempts to connect to "motoX"
             */
            capability.AllowClientIncoming(clientId);

            /*
             * To make an outgoing connection from a device, you'll need to configure a capability token with the SID of a Twilio Application
             * so that Twilio will know what VoiceUrl to use to handle the connection.
             */
            capability.AllowClientOutgoing(ApplicationSid);

            /*
             * If the token expires while the device has an active connection, the connection will not be terminated,
             * but the device will need to be re-initialized with a valid token before attempting
             * or receiving another connection.
             */
            /*
             * Note:- Note that the token generated is valid for 1 hour unless otherwise specified.
             * To specify a different period of time, pass in the number of seconds
             * as an integer parameter to generateToken() -- for example, for a token that expires after 5 minutes,
             * call generateToken(300). The maximum allowed lifetime for a token is 24 hours.
             */
            var token = capability.GenerateToken();

            return(token);
        }
Esempio n. 4
0
        public ActionResult Setup(string id)
        {
            // Load Twilio configuration from Web.config
            var accountSid = ConfigurationManager.AppSettings["TwilioAccountSid"];
            var authToken  = ConfigurationManager.AppSettings["TwilioAuthToken"];
            var appSid     = ConfigurationManager.AppSettings["TwilioTwimlAppSid"];

            if (string.IsNullOrWhiteSpace(id))
            {
                // Create a random identity for the client
                id = Internet.UserName().AlphanumericOnly();
            }

            // Create an Access Token generator
            var capability = new TwilioCapability(accountSid, authToken);

            capability.AllowClientOutgoing(appSid);
            capability.AllowClientIncoming(id);
            var token = capability.GenerateToken();

            return(Json(new
            {
                id,
                token
            }, JsonRequestBehavior.AllowGet));
        }
        public static string Generate(string agentId)
        {
            var twilioCapability = new TwilioCapability(Config.AccountSID, Config.AuthToken);

            twilioCapability.AllowClientIncoming(agentId);
            return(twilioCapability.GenerateToken());
        }
Esempio n. 6
0
        public string Generate(string role)
        {
            var capability = new TwilioCapability(_credentials.AccountSID, _credentials.AuthToken);

            capability.AllowClientOutgoing(_credentials.TwiMLApplicationSID);
            capability.AllowClientIncoming(role);

            return(capability.GenerateToken());
        }
        public ActionResult Token(string clientName)
        {
            var capability = new TwilioCapability(Credentials.AccountSid, Credentials.AuthToken);

            capability.AllowClientIncoming(clientName);
            capability.AllowClientOutgoing("AP08b4c661205ac48c6e896a83fc12aec1");
            var token = capability.GenerateToken();

            return(Content(token));
        }
Esempio n. 8
0
        public ActionResult Agent(string id)
        {
            var capability = new TwilioCapability(Settings.AccountSid, Settings.AuthToken);

            capability.AllowClientIncoming(id);
            capability.AllowClientOutgoing(ApplicationSid);

            ViewBag.token = capability.GenerateToken();

            return(View());
        }
Esempio n. 9
0
        public ActionResult Token()
        {
            var capabilities = new TwilioCapability(
                "REPLACE_WITH_YOUR_TWILIO_ACCOUNT_SID",
                "REPLACE_WITH_YOUR_TWILIO_AUTH_TOKEN");

            capabilities.AllowClientIncoming("REPLACE_WITH_A_CLIENT_NAME");
            capabilities.AllowClientOutgoing("REPLACE_WITH_YOUR_TWIML_APPLICATION_SID");
            var token = capabilities.GenerateToken();

            return(Content(token));
        }
Esempio n. 10
0
        public ActionResult Token()
        {
            var capabilities = new TwilioCapability(
                "AC8db6e2f879ef3a704783bda510da04c9",
                "ff3f5a2709685a9acf6c505f3c28175c");

            capabilities.AllowClientIncoming("damien");
            capabilities.AllowClientOutgoing("APbaa0fe579c87c193eb4dad01db831cea");
            var token = capabilities.GenerateToken();

            return(Content(token));
        }
Esempio n. 11
0
    // GET: Token
    public ActionResult Index()
    {
        // put your Twilio API credentials here
        string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        string authToken  = "your_auth_token";

        var capability = new TwilioCapability(accountSid, authToken);

        capability.AllowClientIncoming("jenny");
        string token = capability.GenerateToken();

        return(Content(token, "application/jwt"));
    }
        // GET: Client/Token?ClientName=alice
        public ActionResult Token(string clientName = _clientName)
        {
            // Create a TwilioCapability object passing in your credentials.
            var capability = new TwilioCapability(AccoutnSID, AuthToken);

            // Specify that this token allows receiving of incoming calls
            capability.AllowClientIncoming(clientName);

            // Replace "AP*****" with your TwiML App Sid
            capability.AllowClientOutgoing(TwiMLAppSID);

            // Return the token as text
            return(Content(capability.GenerateToken()));
        }
Esempio n. 13
0
        // GET: Client
        public ActionResult Token(string clientName)
        {
            if (String.IsNullOrEmpty(clientName))
            {
                clientName = "default";
            }

            var capability = new TwilioCapability(Credentials.AccountSid, Credentials.AuthToken);

            capability.AllowClientIncoming(clientName);
            capability.AllowClientOutgoing(Credentials.AppSid);

            return(Content(capability.GenerateToken()));
        }
    // GET: Token
    public ActionResult Index()
    {
        // put your Twilio API credentials here
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken  = "your_auth_token";

        // put your Twilio Application SID here
        const string appSid = "APXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

        var capability = new TwilioCapability(accountSid, authToken);

        capability.AllowClientOutgoing(appSid);
        var token = capability.GenerateToken();

        return(Content(token, "application/jwt"));
    }
Esempio n. 15
0
        public async Task <HttpResponseMessage> GetVoiceCallToken()
        {
            var customerPhoneNumber = await agentService.GetAssociatedCustomerPhoneNumber(UserIdentityID);

            var capability = new TwilioCapability(settings.Account.Sid, settings.AuthToken);

            capability.AllowClientOutgoing(settings.AppSid);

            var response = new ApiResponse <TwilioVoiceToken>(new TwilioVoiceToken
            {
                Identity    = UserIdentityID,
                Token       = capability.GenerateToken(),
                PhoneNumber = customerPhoneNumber
            });

            return(SendHttpResponse(response));
        }