Exemple #1
0
        public string createMember(string identity, string channelSId, string attributes)
        {
            var memberResource = MemberResource.Create(
                identity: identity,
                pathServiceSid: ServiceId,
                pathChannelSid: channelSId,
                attributes: attributes
                );

            return(memberResource.Sid);
        }
        public ActionResult DirectMessage(string Receiver)
        {
            try
            {
                string          userId   = User.Identity.GetUserId();
                ApplicationUser receiver = db.Users.Where(u => u.UserName == Receiver).First();
                ApplicationUser sender   = db.Users.Where(u => u.Id == userId).First();

                ViewBag.UserName = sender.UserName;
                ViewBag.Receiver = receiver.UserName;
                DirectMessageChannel dmChannel = null;

                // API Connect
                TwilioClient.Init(TwilioApiKeys.accountSid, TwilioApiKeys.authToken);

                try
                {
                    dmChannel = db.DirectMessageChannels.Where(dm => dm.ReciverId.Id == receiver.Id && dm.SenderId.Id == sender.Id || dm.ReciverId.Id == sender.Id && dm.SenderId.Id == receiver.Id).First();
                    return(View(MessageResource.Read(TwilioApiKeys.serviceSid, dmChannel.ChannelId)));
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }


                if (dmChannel == null)
                {
                    // API Create channel
                    var channel = ChannelResource.Create(TwilioApiKeys.serviceSid, friendlyName: "DM Channel", uniqueName: $"{sender.UserName}-{receiver.UserName}", type: ChannelResource.ChannelTypeEnum.Private);

                    // Database DMChannel
                    dmChannel           = new DirectMessageChannel();
                    dmChannel.ChannelId = channel.Sid;
                    dmChannel.ReciverId = receiver;
                    dmChannel.SenderId  = sender;

                    // API Add members
                    MemberResource.Create(TwilioApiKeys.serviceSid, channel.Sid, dmChannel.ReciverId.UserName);
                    MemberResource.Create(TwilioApiKeys.serviceSid, channel.Sid, dmChannel.SenderId.UserName);

                    // Save DMChannel to Database
                    db.DirectMessageChannels.Add(dmChannel);
                    db.SaveChanges();

                    return(View(MessageResource.Read(TwilioApiKeys.serviceSid, channel.Sid)));
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            return(View("Index"));
        }
        public void TestCreateResponse()
        {
            var twilioRestClient = Substitute.For <ITwilioRestClient>();

            twilioRestClient.AccountSid.Returns("ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
            twilioRestClient.Request(Arg.Any <Request>())
            .Returns(new Response(
                         System.Net.HttpStatusCode.Created,
                         "{\"sid\": \"MBaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"account_sid\": \"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"channel_sid\": \"CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"service_sid\": \"ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"identity\": \"jing\",\"role_sid\": \"RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"last_consumed_message_index\": null,\"last_consumption_timestamp\": null,\"date_created\": \"2016-03-24T21:05:50Z\",\"date_updated\": \"2016-03-24T21:05:50Z\",\"url\": \"https://chat.twilio.com/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Members/MBaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"}"
                         ));

            var response = MemberResource.Create("ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "Identity", client: twilioRestClient);

            Assert.NotNull(response);
        }
Exemple #4
0
    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 member = MemberResource.Create(
            identity: "Identity",
            pathServiceSid: "ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
            pathChannelSid: "CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
            );

        Console.WriteLine(member.Sid);
    }
Exemple #5
0
        public object AddMember(InputAddMember input)
        {
            var serviceSid     = input.ServiceSid;
            var pathChannelSid = input.ChannelSid;
            var roleSid        = input.RoleSid;
            var indentity      = input.Identity;

            var member = MemberResource.Create(
                identity: indentity,
                pathServiceSid: serviceSid,
                pathChannelSid: pathChannelSid,
                roleSid: roleSid
                );

            return(member);
        }
    static void Main(string[] args)
    {
        // Find your Account SID and Auth Token at twilio.com/console
        const string accountSid = "accountSid";
        const string authToken  = "authToken";
        const string serviceSid = "serviceSid";
        const string channelSid = "channelSid";
        const string identity   = "identity";

        TwilioClient.Init(accountSid, authToken);

        // Add a member
        var member = MemberResource.Create(serviceSid, channelSid, identity);

        Console.WriteLine(member);
    }
Exemple #7
0
    static void Main(string[] args)
    {
        // Find your Account SID and Auth Token at twilio.com/console
        // To set up environmental variables, see http://twil.io/secure
        const string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");
        const string authToken  = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN");
        const string serviceSid = Environment.GetEnvironmentVariable("TWILIO_SERVICE_SID");
        const string channelSid = "CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string identity   = "identity";

        TwilioClient.Init(accountSid, authToken);

        // Add a member
        var member = MemberResource.Create(serviceSid, channelSid, identity);

        Console.WriteLine(member);
    }
        public void TestCreateRequest()
        {
            var twilioRestClient = Substitute.For <ITwilioRestClient>();
            var request          = new Request(
                HttpMethod.Post,
                Twilio.Rest.Domain.Chat,
                "/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Members",
                ""
                );

            request.AddPostParam("Identity", Serialize("Identity"));
            twilioRestClient.Request(request).Throws(new ApiException("Server Error, no content"));

            try
            {
                MemberResource.Create("ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "Identity", client: twilioRestClient);
                Assert.Fail("Expected TwilioException to be thrown for 500");
            }
            catch (ApiException) {}
            twilioRestClient.Received().Request(request);
        }
        public ActionResult Create([Bind(Include = "Id,Name,OpenDate,StreetAddress,City,State,ZipCode,Phone,Email,AcceptChildrenUnderAgeTwo,AcceptDisabilites,MaxChildren,CurrentlyAcceptingApplicants,ChannelId,DailyRatePerChild")] DayCare dayCare)
        {
            if (ModelState.IsValid)
            {
                var holder = User.Identity.GetUserId();
                var same   = db.Users.Where(s => s.Id == holder).FirstOrDefault();
                dayCare.UserId = same;

                TwilioClient.Init(TwilioApiKeys.accountSid, TwilioApiKeys.authToken);
                var channel = ChannelResource.Create(TwilioApiKeys.serviceSid, friendlyName: dayCare.Name, type: ChannelResource.ChannelTypeEnum.Private);
                dayCare.ChannelId = channel.Sid;
                MemberResource.Create(TwilioApiKeys.serviceSid, channel.Sid, "Admin");
                MemberResource.Create(TwilioApiKeys.serviceSid, channel.Sid, dayCare.UserId.UserName);

                db.DayCares.Add(dayCare);
                db.SaveChanges();
                return(RedirectToAction("Index", "Users"));
            }

            return(View(dayCare));
        }
        public void TestCreateRequest()
        {
            var twilioRestClient = Substitute.For <ITwilioRestClient>();
            var request          = new Request(
                HttpMethod.Post,
                Twilio.Rest.Domain.IpMessaging,
                "/v2/Services/ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Channels/CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Members",
                ""
                );

            request.AddPostParam("Identity", Serialize("identity"));
            request.AddHeaderParam("X-Twilio-Webhook-Enabled", Serialize(MemberResource.WebhookEnabledTypeEnum.True));
            twilioRestClient.Request(request).Throws(new ApiException("Server Error, no content"));

            try
            {
                MemberResource.Create("ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "identity", xTwilioWebhookEnabled: Serialize(MemberResource.WebhookEnabledTypeEnum.True), client: twilioRestClient);
                Assert.Fail("Expected TwilioException to be thrown for 500");
            }
            catch (ApiException) {}
            twilioRestClient.Received().Request(request);
        }
        public ActionResult AcceptApplication(int?applicationId)
        {
            var     user        = User.Identity.GetUserId();
            var     application = db.Applications.Where(a => a.Parent.Id == applicationId).Select(p => p).FirstOrDefault();
            DayCare dayCare     = db.DayCares.Where(u => u.UserId.Id == user).Select(s => s).FirstOrDefault();

            dayCare.Parents.Add(application.Parent);
            var kids = new List <Child>();

            foreach (var kid in application.Parent.Children)
            {
                dayCare.Children.Add(kid);
            }
            application.Status = "Approved";
            dayCare.PendingApplications.Remove(application);

            // Add parent to daycare group chat channel
            TwilioClient.Init(TwilioApiKeys.accountSid, TwilioApiKeys.authToken);
            MemberResource.Create(TwilioApiKeys.serviceSid, dayCare.ChannelId, application.Parent.UserId.UserName);

            db.SaveChanges();
            TempData["Message"] = "**Successfully added a new family to your day care!";
            return(RedirectToAction("ViewPendingApplications"));
        }