Esempio n. 1
0
        public void HubtrlMessage(string num, string info)
        {
            const string clientId     = "eesuojtu";
            const string clientSecret = "shfgzcjx ";

            //try
            //{
            var             host       = new ApiHost(new BasicAuth(clientId, clientSecret));
            var             messageApi = new MessagingApi(host);
            MessageResponse msg        = messageApi.SendQuickMessage("COCA-COLA", num, info, true);

            Console.WriteLine(msg.Status);
            //}
            //catch (Exception e)
            //{
            //    if (e.GetType() == typeof(HttpRequestException))
            //    {
            //        var ex = e as HttpRequestException;
            //        if (ex != null && ex.HttpResponse != null)
            //        {
            //            Console.WriteLine("Error Status Code " + ex.HttpResponse.Status);
            //        }
            //    }
            //    throw;
            //}

            //Console.ReadKey();
        }
Esempio n. 2
0
        private static void Main(string[] args)
        {
            const string clientId     = "clientId";
            const string clientSecret = "clientSecret";


            try {
                var             host       = new ApiHost(new BasicAuth(clientId, clientSecret));
                var             messageApi = new MessagingApi(host);
                MessageResponse msg        = messageApi.SendQuickMessage("DevUniverse", "+233207110652", "Welcome to planet Hubtel!", true);
                Console.WriteLine(msg.Status);
            }
            catch (Exception e) {
                if (e.GetType() == typeof(HttpRequestException))
                {
                    var ex = e as HttpRequestException;
                    if (ex != null && ex.HttpResponse != null)
                    {
                        Console.WriteLine("Error Status Code " + ex.HttpResponse.Status);
                    }
                }
                throw;
            }

            Console.ReadKey();
        }
Esempio n. 3
0
        public void CampaignSms(CampaignDto model)
        {
            // var phoneNumbers = from p in _db.Donors
            //select new { p.Phone };

            string clientId     = _config.GetValue <string>("Sms:ClientId");
            string clientSecret = _config.GetValue <string>("Sms:ClientSecret");

            StringBuilder builder = new StringBuilder();

            builder.Append("Donor Trace Campaign");
            builder.AppendLine();
            builder.Append("Organization: " + " " + model.Organization);
            builder.AppendLine();
            builder.Append("Description: " + " " + model.Description);
            builder.AppendLine();
            builder.Append("Location: " + " " + model.Location);
            builder.AppendLine();
            builder.Append("Date: " + " " + model.EventDate);


            var host       = new ApiHost(new BasicAuth(clientId, clientSecret));
            var messageApi = new MessagingApi(host);
            // foreach (var p in phoneNumbers)
            // {
            MessageResponse msg = messageApi.SendQuickMessage("Donor Trace", "0242229571", builder.ToString(), true);
            //}

            // return Ok();
        }
        public MessagingClient()
        {
            System.Collections.Specialized.NameValueCollection appSettings =
                ConfigurationManager.AppSettings;

            if (!appSettings.HasKeys()) {
                throw new ConfigurationErrorsException("No app.settings options found.");
            }

            string accountId = appSettings.Get("SoftLayer.Messaging.AccountID");
            string userName = appSettings.Get("SoftLayer.Messaging.UserName");
            string apiKey = appSettings.Get("SoftLayer.Messaging.APIKey");
            this.dataCenter = appSettings.Get("SoftLayer.Messaging.DataCenter");
            bool usePrivateEndpoint = false;

            try {
                usePrivateEndpoint = Convert.ToBoolean(
                    appSettings.Get("SoftLayer.Messaging.PrivateEndpoint"));
            }
            catch (FormatException e) {
                throw new FormatException("PrivateEndpoint must be either true or false.", e);
            }

            this.endpointConfig = new EndpointConfig();
            this.endpointConfig.Load();

            this.client = new MessagingApi(accountId, userName, apiKey,
                endpointConfig.GetUrlForDatacenter(this.dataCenter, usePrivateEndpoint));
        }
Esempio n. 5
0
        private static void Main(string[] args)
        {
            const string clientId     = "hqikydyh";
            const string clientSecret = "kakdxpvd";


            try {
                var             host       = new ApiHost(new BasicAuth(clientId, clientSecret));
                var             messageApi = new MessagingApi(host);
                MessageResponse msg        = messageApi.SendQuickMessage("Arsene", "+233247063817", "Hello Big Bro!", true);
                Console.WriteLine(msg.Status);
            }
            catch (Exception e) {
                if (e.GetType() == typeof(HttpRequestException))
                {
                    var ex = e as HttpRequestException;
                    if (ex != null && ex.HttpResponse != null)
                    {
                        Console.WriteLine("Error Status Code " + ex.HttpResponse.Status);
                    }
                }
                throw;
            }

            Console.ReadKey();
        }
Esempio n. 6
0
        private static void Main(string[] args)
        {
            const string clientId     = "mcjntyvj";
            const string clientSecret = "csidlcvn";


            try {
                var             host       = new ApiHost(new BasicAuth(clientId, clientSecret));
                var             messageApi = new MessagingApi(host);
                MessageResponse msg        = messageApi.SendQuickMessage("BPCI", "+233274323816", "Welcome to BPCI HQ!", false);
                Console.WriteLine(msg.Status);
            }
            catch (Exception e) {
                if (e.GetType() == typeof(HttpRequestException))
                {
                    var ex = e as HttpRequestException;
                    if (ex != null && ex.HttpResponse != null)
                    {
                        Console.WriteLine("Error Status Code " + ex.HttpResponse.Status);
                    }
                }
                throw;
            }

            Console.ReadKey();
        }
Esempio n. 7
0
        public void SendBulkSMS()
        {
            var             host       = new ApiHost(new BasicAuth(ClientCredentials.GetClientId(), ClientCredentials.GetSecret()));
            var             messageApi = new MessagingApi(host);
            MessageResponse msg        = messageApi.SendQuickMessage(MessageId, Phone, MessageBody, RegisteredDelivery);

            Console.WriteLine("Message Sent Successfully to  " + Phone);
        }
        public MessagingClient(string accountId, string userName, string apiKey, string dataCenter, bool usePrivateEndpoint = false)
        {
            EndpointConfig endpointConfig = new EndpointConfig();
            endpointConfig.Load();
            string apiEndpoint = endpointConfig.GetUrlForDatacenter(dataCenter, usePrivateEndpoint);

            this.client = new MessagingApi(accountId, userName, apiKey, apiEndpoint);
            this.UsePrivateEndpoint = usePrivateEndpoint;
            this.dataCenter = dataCenter;
        }
Esempio n. 9
0
        public int doSMSJob()
        {
            string formattedPhone = "";

            var host = new ApiHost(new BasicAuth(ClientCredentials.GetClientId(), ClientCredentials.GetSecret()));

            if (MessageLogger.EnableLogging == true)
            {
                MessageLogger.LogStatus(MessageLogger.LogPath, "Starting New Batch.............................................................");
                MessageLogger.LogStatus(MessageLogger.LogPath, "Establishing Server Connection");
            }

            var messageApi = new MessagingApi(host);


            foreach (var phone in Phone.PhoneNumbers)
            {
                if (MessageLogger.EnableLogging == true)
                {
                    MessageLogger.LogStatus(MessageLogger.LogPath, "Sending to........ " + phone);
                }

                //Remove 0 and add +233 to the beginning of the phone numbers
                if (Phone.FormatLocal == true)
                {
                    formattedPhone = Phone.Validate(phone);
                }

                //checking the Ghanaian standard mobile length
                if (phone.Length < 10)
                {
                    // log unsent message to outBox
                    MessageLogger.logOutbox(formattedPhone, "Rejected due to length < 10");
                    continue;
                }
                else
                {
                    try
                    {
                        MessageResponse msge = messageApi.SendQuickMessage(MessageId, formattedPhone, MessageBody, RegisteredDelivery);
                        MessageLogger.logSent(formattedPhone, "Successful");
                    }
                    catch (Exception e)
                    {
                        MessageLogger.logOutbox(formattedPhone, "rejected due to server error !");
                        //pass control to the next iteration of the enclosing foreach statement
                        continue;
                    }
                }
            }
            //returns number of sent >1 when successful
            return(MessageLogger.sent.Count);
        }
Esempio n. 10
0
        public void SendSms(OfficerDto officer)
        {
            string clientId     = _config.GetValue <string>("Sms:ClientId");
            string clientSecret = _config.GetValue <string>("Sms:ClientSecret");

            StringBuilder builder = new StringBuilder();

            builder.Append("You have been registered on the Donor Trace Mobile App");
            builder.AppendLine();
            builder.Append("Username: "******" " + officer.UserName);
            builder.AppendLine();
            builder.Append("Password: "******" " + officer.Password);

            var             host       = new ApiHost(new BasicAuth(clientId, clientSecret));
            var             messageApi = new MessagingApi(host);
            MessageResponse msg        = messageApi.SendQuickMessage("Donor Trace", officer.ContactNo, builder.ToString(), true);
        }
Esempio n. 11
0
        public async Task <IActionResult> Sms(SmsDto sms)
        {
            string clientId     = _config.GetValue <string>("Sms:ClientId");
            string clientSecret = _config.GetValue <string>("Sms:ClientSecret");

            StringBuilder builder = new StringBuilder();

            builder.Append("You have been registered on the Donor Trace Mobile App");


            var host       = new ApiHost(new BasicAuth(clientId, clientSecret));
            var messageApi = new MessagingApi(host);

            MessageResponse msg = messageApi.SendQuickMessage("Donor Trace", sms.To, builder.ToString(), false);

            return(Ok(msg.Status));
        }
Esempio n. 12
0
        public async Task <Player> WithMessaging()
        {
            if (string.IsNullOrEmpty(Token))
            {
                throw new Exception("Can't invoke Player.WithMessaging() without being connected");
            }

            _messaging = new MessagingApi(Token);

            await _messaging.Connect();

            // Subscribe to player channel
            Notifications        = new NotificationsApi(_api.GetHttp(), _messaging);
            _playerNotifications = await Notifications.Subscribe(AppId, "player", Id);

            return(this);
        }
Esempio n. 13
0
        static void Main(string[] args)
        {
            var config = new Configuration();

            config.BasePath = "https://tapi.telstra.com/v2";
            var apiInstance  = new AuthenticationApi(config);
            var clientId     = Environment.GetEnvironmentVariable("CLIENT_ID");     // string |
            var clientSecret = Environment.GetEnvironmentVariable("CLIENT_SECRET"); // string |
            var grantType    = "client_credentials";                                // string |  (default to "client_credentials")
            var scope        = "NSMS";                                              // string | NSMS (optional)

            try
            {
                // Generate OAuth2 token
                OAuthResponse result = apiInstance.AuthToken(clientId, clientSecret, grantType, scope);
                Console.WriteLine("Token acquired!");
                config.AccessToken = result.AccessToken;

                var provisioningInstance = new ProvisioningApi(config);
                var body = new ProvisionNumberRequest(30);
                ProvisionNumberResponse provisioningResult = provisioningInstance.CreateSubscription(body);
                Console.WriteLine("Number provisioned!");

                var smsApiInstance = new MessagingApi(config);
                var payload        = new SendSMSRequest(
                    Environment.GetEnvironmentVariable("PHONE_NO"),
                    "Test C# SDK",
                    Environment.GetEnvironmentVariable("FROM_ALIAS"));

                MessageSentResponseSms smsResult = smsApiInstance.SendSMS(payload);
                Console.WriteLine("Message sent");
            }
            catch (ApiException e)
            {
                Console.WriteLine("Exception when calling AuthenticationApi.AuthToken: " + e.Message);
                Console.WriteLine("Status Code: " + e.ErrorCode);
                Console.WriteLine(e.StackTrace);
                throw;
            }
        }
Esempio n. 14
0
 public void Init()
 {
     instance = new MessagingApi();
 }
 public MessagingApiTests()
 {
     instance = new MessagingApi();
 }
Esempio n. 16
0
 public NotificationsApi(HttpUtils http, MessagingApi messagingApi) : base(http, "/notifications")
 {
     _messagingApi = messagingApi;
 }