Example #1
0
    def sendSMSMessage(self, message, to, retry=0):
        if to.startswith("+1"):
            try:
                message = "Garage Door Alert - %s " % message

                message = clicksend_client.SmsMessage(body=message, to=to)
                messages = clicksend_client.SmsMessageCollection(
                    messages=[message])
                try:
                    # Send sms message(s)
                    api_response = self.smsAPI.sms_send_post(messages)
                    # print(api_response)
                except ApiException as e:
                    print(
                        "Exception when calling SMSApi->sms_send_post: %s\n" %
                        e)
            except ConnectionResetError as err:
                print("Got an error sending SMS trying again...")
                time.sleep(1)
                if retry < 3:
                    retry += 1
                    self.sendSMSMessage(message, to, retry)
                else:
                    print(
                        "Still couldn't send that dang message. Giving up after 3 retries"
                    )

        else:
            print("Invalid phone number while trying to send message")
Example #2
0
def textSender():

    configuration = clicksend_client.Configuration()
    configuration.username = ''
    configuration.password = ''


    # create an instance of the API class
    api_instance = clicksend_client.SMSApi(clicksend_client.ApiClient(configuration))

    # If you want to explictly set from, add the key _from to the message.
    sms_message = SmsMessage(source="sdk",
                        body="Delivery Driver needed for Cake's Bakery. Contact at 214-557-4834",
                        to=""
                       )

    sms_messages = clicksend_client.SmsMessageCollection(messages=[sms_message])

    try:
        # Send sms message(s)
        api_response = api_instance.sms_send_post(sms_messages)
        print(api_response)
        return(jsonify(api_response))
    except ApiException as e:
        print("Exception when calling SMSApi->sms_send_post: %s\n" % e)
        return("error")
Example #3
0
def send_sms(request):
    if request.method == "POST":
        data = json.loads(request.body.decode("utf-8"))
        print("Sending SMS: {}".format(data))

        sms_message = SmsMessage(source="api",
                                 body=data["message_body"],
                                 to="+972{}".format(data["number"]),
                                 schedule=data["schedule"])
        sms_messages = clicksend_client.SmsMessageCollection(
            messages=[sms_message])

        try:
            api_response = ast.literal_eval(
                api_instance.sms_send_post(sms_messages))
            # save sms only if it is scheduled and we have project_id
            if data["project_id"] and data["schedule"]:
                # first cancel any scheduled messages for this project_id
                cancel_sms_by_project_id(data["project_id"])
                # now save new scheduled sms
                message_id = api_response["data"]["messages"][0]["message_id"]
                Sms(number=data["number"],
                    message_id=message_id,
                    project_id=data["project_id"]).save()
        except ApiException as e:
            print(
                "Exception when calling SMSApi->sms_send_post: {}\n".format(e))
        return HttpResponse("")
 def notify(self, to, msg):
     sms_message = SmsMessage(source="python", body=msg, to=f"+91{to}")
     sms_messages = clicksend_client.SmsMessageCollection(
         messages=[sms_message])
     try:
         # Send sms message(s)
         api_response = self.api_instance.sms_send_post(sms_messages)
         print(api_response)
     except ApiException as e:
         print("Exception when calling SMSApi->sms_send_post: %s\n" % e)
Example #5
0
    def __init__(self):
        print("Initializing Garage Door Monitor")
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(self.BEAM_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)
        #GPIO.add_event_detect(self.BEAM_PIN, GPIO.BOTH, callback=self.break_beam_callback)
        
        atexit.register(self.exitHandler)

        config = configparser.ConfigParser()
        config.read('settings.conf')


        # While there is no internet... run a continously loop.
        # THIS IS BLOCKING THE ENTIRE STATUS CHECK SCRIPT!
        noInternetCount = 0
        while not self.internet():
            print("No internet %s!!!" % noInternetCount)

            noInternetCount += 1
            time.sleep(5)

        # Configure HTTP basic authorization: BasicAuth
        username = config['Notifications']['clicksendAPI_username']
        password = config['Notifications']['clicksendAPI_password']
        notificationNumber = config['Notifications']['phonenumber']
        notificationNumber2 = config['Notifications']['benjaminWork']
        notificationNumber3 = config['Notifications']['annaCell']
        configuration = clicksend_client.Configuration()
        configuration.username = username
        configuration.password = password

        # create an instance of the API class
        self.api_instance = clicksend_client.SMSApi(clicksend_client.ApiClient(configuration))

        # If you want to explictly set from, add the key _from to the message.
        sms_message = SmsMessage(source="python",
                        body="Hey, the garage door has been open for five minutes.",
                        to=notificationNumber)
        sms_message2 = SmsMessage(source="python",
                        body="Hey, the garage door has been open for several minutes.",
                        to=notificationNumber2)

        sms_message3 = SmsMessage(source="python",
                        body="Hey, the garage door has been open for several minutes.",
                        to=notificationNumber3)

        self.sms_messages = clicksend_client.SmsMessageCollection(messages=[sms_message,sms_message2,sms_message3])


        garageDoorStatusThread = threading.Thread(target=self.doorStatusLoop)
        sendSMSThread = threading.Thread(target=self.sendSMS)


        garageDoorStatusThread.start()
        sendSMSThread.start()
Example #6
0
    def send_sms(self, phone, code):
        api_instance = clicksend_client.SMSApi(clicksend_client.ApiClient(configuration))

        sms_message = SmsMessage(source="php",
                                 body="Your security code for MEDD is {}".format(code),
                                 to=phone,
                                 schedule=1436874701)

        sms_messages = clicksend_client.SmsMessageCollection(messages=[sms_message])

        try:
            # Send sms message(s)
            api_response = api_instance.sms_send_post(sms_messages)
            print(api_response)
        except ApiException as e:
            print("Exception when calling SMSApi->sms_send_post: %s\n" % e)
Example #7
0
    def send_invite_sms(self, company, phone, link):
        api_instance = clicksend_client.SMSApi(clicksend_client.ApiClient(configuration))

        sms_message = SmsMessage(source="php",
                                 body="Hello! Your company {} "
                                      "invited you as a representative manager to the MEDD platform."
                                      " Please, follow this link and confirm your participation {}".format(company, link),
                                 to=phone,
                                 schedule=1436874701)

        sms_messages = clicksend_client.SmsMessageCollection(messages=[sms_message])

        try:
            # Send sms message(s)
            api_response = api_instance.sms_send_post(sms_messages)
            print(api_response)
        except ApiException as e:
            print("Exception when calling SMSApi->sms_send_post: %s\n" % e)
Example #8
0
def main():
    # create an instance of the API class
    api_instance = clicksend_client.SMSApi(
        clicksend_client.ApiClient(configuration))
    sms_message = SmsMessage(source="sdk",
                             body="This is the body of the message.",
                             country='US',
                             to="+13129709819")
    sms_messages = clicksend_client.SmsMessageCollection(
        messages=[sms_message])
    try:
        # Send sms message(s)
        api_response = api_instance.sms_send_post(sms_messages)
        sent_list = api_response['data']['messages']
        print(sent_list)
        # then - https://developers.clicksend.com/docs/rest/v3/?python#view-sms-receipts
        # https://developers.clicksend.com/docs/rest/v3/#create-test-sms-receipt
        # inbound https://developers.clicksend.com/docs/rest/v3/#view-inbound-sms
    except ApiException as e:
        print("Exception when calling SMSApi->sms_send_post: %s\n" % e)
    return
Example #9
0
                if url['LastNum'] > 0:
                    msg += f"{url['Company']}: Old:{url['LastNum']}, Current:{num}\n"
                s = f"update JodyEmployees set LastNum = {num} where intID = {url['intID']}"
                SQLExec(s, cursor, conn)

    if msg != "":
        configuration = clicksend_client.Configuration()
        configuration.username = smsUser
        configuration.password = smsPass

        api_instance = clicksend_client.SMSApi(
            clicksend_client.ApiClient(configuration))
        toSend = []
        for phone in phones:

            toSend.append(
                SmsMessage(source="python", _from=srcPhone, body=msg,
                           to=phone))
        sms_messages = clicksend_client.SmsMessageCollection(messages=toSend)

        try:
            api_response = api_instance.sms_send_post(sms_messages)
            print(api_response)
        except ApiException as e:
            print("Exception when calling SMSApi->sms_send_post: %s\n" % e)

    s = "update JodyConfig set LastChecked = getdate()"
    SQLExec(s, cursor, conn)

driver.close()
conn.close()