示例#1
0
        public void SendSms(string to, string smsmessage)
        {
            var configuration = new Configuration()
            {
                // Username = USERNAME,
                // Password = API_KEY
            };
            var smsApi = new SMSApi(configuration);

            var listOfSms = new List <SmsMessage> {
                new SmsMessage(to: to, body: smsmessage, source: "sdk")
            };

            var smsCollection = new SmsMessageCollection(listOfSms);
            var response      = smsApi.SmsSendPost(smsCollection);
        }
        private async Task <bool> SendSMSAsync(string number, string message)
        {
            var userName = Environment.GetEnvironmentVariable("clickSendUser");
            var apiKey   = Environment.GetEnvironmentVariable("clickSendApiKey");
            var config   = new IO.ClickSend.Client.Configuration();

            config.Username = userName;
            config.Password = apiKey;
            var clickSend  = new SMSApi(config);
            var smsMessage = new SmsMessage(null, message, number);

            var sms = new List <SmsMessage>()
            {
                smsMessage
            };

            var collection   = new SmsMessageCollection(sms);
            var responseTask = clickSend.SmsSendPostAsync(collection);

            var responseString         = await responseTask;
            ClickSendResponse response = JsonSerializer.Deserialize <ClickSendResponse>(responseString);

            if (response.http_code == 200)
            {
                //TODO: there is a 'data' object in the deserializer that lets us know if the text went through
                if (_logger != null)
                {
                    _logger.LogInformation($"We got a positive message back from Clicksend. They say the satus of the message is: {response.data.messages[0].status}");
                }

                return(true);
            }
            if (_logger != null)
            {
                _logger.LogError($"Our attempt to send an sms message failed. Here's what we know. \nHttp response code: {response.http_code} \nResponse message:{response.response_msg}");
            }
            return(false);
        }
示例#3
0
 public void Init()
 {
     instance = new SMSApi();
 }