Пример #1
0
 def __init__(self, leased_phone_number, target_phone_numbers,
              comm_service_connection_string):
     self.leased_phone_number = leased_phone_number
     self.target_phone_numbers = target_phone_numbers
     self.connection_string = comm_service_connection_string
     self.sms_client = SmsClient.from_connection_string(
         self.connection_string)
Пример #2
0
def cf_communication_sms(cli_ctx, kwargs):
    from azure.communication.sms import SmsClient

    connection_string = kwargs.pop('connection_string', None)
    if connection_string is None:
        error_msg = 'Please specify --connection-string, or set AZURE_COMMUNICATION_CONNECTION_STRING.'
        raise RequiredArgumentMissingError(error_msg)

    client = SmsClient.from_connection_string(connection_string)
    return client
    def test_send_sms_unauthorized_from_phone_number(self):

        sms_client = SmsClient.from_connection_string(self.connection_str)

        with pytest.raises(HttpResponseError) as ex:
            # calling send() with sms values
            sms_client.send(from_="+14255550123",
                            to=[self.phone_number],
                            message="Hello World via SMS")

        assert ex.value.message is not None
    def test_send_sms_fake_from_phone_number(self):

        sms_client = SmsClient.from_connection_string(self.connection_str)

        with pytest.raises(HttpResponseError) as ex:
            # calling send() with sms values
            sms_client.send(from_="+15550000000",
                            to=[self.phone_number],
                            message="Hello World via SMS")

        assert str(ex.value.status_code) == "400"
        assert ex.value.message is not None
    def test_send_sms_single(self):

        sms_client = SmsClient.from_connection_string(self.connection_str)

        # calling send() with sms values
        sms_responses = sms_client.send(from_=self.phone_number,
                                        to=self.phone_number,
                                        message="Hello World via SMS")

        assert len(sms_responses) == 1

        self.verify_successful_sms_response(sms_responses[0])
    def setUp(self):
        super(SMSClientTest, self).setUp()
        
        if self.is_playback():
            self.phone_number = "+18000005555"
        else:
            self.phone_number = os.getenv("PHONE_NUMBER")

        self.recording_processors.extend([
            BodyReplacerProcessor(keys=["to", "from", "messageId"]),
            ResponseReplacerProcessor(keys=[self._resource_name])])

        self.sms_client = SmsClient.from_connection_string(self.connection_str)
Пример #7
0
    def send_sms(self):
        connection_string = "COMMUNICATION_SERVICES_CONNECTION_STRING"

        sms_client = SmsClient.from_connection_string(connection_string)

        # calling send() with sms values
        smsresponse = sms_client.send(
            from_phone_number=PhoneNumberIdentifier("<leased-phone-number>"),
            to_phone_numbers=[PhoneNumberIdentifier("<to-phone-number>")],
            message="Hello World via SMS",
            send_sms_options=SendSmsOptions(
                enable_delivery_report=True))  # optional property

        print(smsresponse)
def mysms_AZcom(recepient,value):
    # configuring your account.
    connection_string = os.getenv('COMMUNICATION_SERVICES_CONNECTION_STRING')
    # Creating the Client object which is used to send SMS.
    sms_client = SmsClient.from_connection_string(connection_string)
    from_phone="xxxxxxxxxx"
    if to_phone:
        //do nothing
    else:
        logging.info('couldnt get recepient phone number')
    if value:
        //do nothing
    else:
        //asuming it is intentional for testing
    def test_send_sms_multiple_with_options(self):

        sms_client = SmsClient.from_connection_string(self.connection_str)

        # calling send() with sms values
        sms_responses = sms_client.send(
            from_=self.phone_number,
            to=[self.phone_number, self.phone_number],
            message="Hello World via SMS",
            enable_delivery_report=True,  # optional property
            tag="custom-tag")  # optional property

        assert len(sms_responses) == 2

        self.verify_successful_sms_response(sms_responses[0])
        self.verify_successful_sms_response(sms_responses[1])
    def test_send_sms_fake_to_phone_number(self):

        sms_client = SmsClient.from_connection_string(self.connection_str)

        # calling send() with sms values
        sms_responses = sms_client.send(from_=self.phone_number,
                                        to=["+15550000000"],
                                        message="Hello World via SMS")

        assert len(sms_responses) == 1

        assert sms_responses[0].message_id is None
        assert sms_responses[0].http_status_code == 400
        assert sms_responses[
            0].error_message == "Invalid To phone number format."
        assert not sms_responses[0].successful
    def send_sms_to_single_recipient(self):
        sms_client = SmsClient.from_connection_string(self.connection_string)

        # calling send() with sms values
        sms_responses = sms_client.send(
            from_=self.phone_number,
            to=self.phone_number,
            message="Hello World via SMS",
            enable_delivery_report=True, # optional property
            tag="custom-tag") # optional property
        sms_response = sms_responses[0]
        
        if (sms_response.successful):
            print("Message with message id {} was successful sent to {}"
            .format(sms_response.message_id, sms_response.to))
        else:
            print("Message failed to send to {} with the status code {} and error: {}"
            .format(sms_response.to, sms_response.http_status_code, sms_response.error_message))
    def test_send_sms_unique_message_ids(self):

        sms_client = SmsClient.from_connection_string(self.connection_str)

        # calling send() with sms values
        sms_responses_1 = sms_client.send(from_=self.phone_number,
                                          to=[self.phone_number],
                                          message="Hello World via SMS")

        # calling send() again with the same sms values
        sms_responses_2 = sms_client.send(from_=self.phone_number,
                                          to=[self.phone_number],
                                          message="Hello World via SMS")

        self.verify_successful_sms_response(sms_responses_1[0])
        self.verify_successful_sms_response(sms_responses_2[0])
        # message ids should be unique due to having a different idempotency key
        assert sms_responses_1[0].message_id != sms_responses_2[0].message_id
Пример #13
0
    def send_sms_to_multiple_recipients(self):
        sms_client = SmsClient.from_connection_string(self.connection_string)

        # calling send() with sms values
        sms_responses = sms_client.send(
            from_="<leased-phone-number>",
            to=[
                "<to-phone-number-1>", "<to-phone-number-2>",
                "<to-phone-number-3>"
            ],
            message="Hello World via SMS",
            enable_delivery_report=True,  # optional property
            tag="custom-tag")  # optional property

        for sms_response in sms_responses:
            if (sms_response.successful):
                print("Message with message id {} was successful sent to {}".
                      format(sms_response.message_id, sms_response.to))
            else:
                print(
                    "Message failed to send to {} with the status code {} and error: {}"
                    .format(sms_response.to, sms_response.http_status_code,
                            sms_response.error_message))
Пример #14
0
import os
from azure.communication.sms import SmsClient

try:
    # Quickstart code goes here
    # Create the SmsClient object which will be used to send SMS messages
    sms_client = SmsClient.from_connection_string("<connection_string>")

    ## Send a 1:1 SMS Message
    # calling send() with sms values
    # sms_responses = sms_client.send(
    # from_="<from-phone-number>",
    # to="<to-phone-number>",
    # message="Hello World via SMS",
    # enable_delivery_report=True, # optional property
    # tag="custom-tag") # optional property

    # Send a 1:N SMS Message
    # calling send() with sms values
    sms_responses = sms_client.send(
        from_="<from-phone-number>",
        to=["<to-phone-number-1>", "<to-phone-number-2>"],
        message="Hello World via SMS Python",
        enable_delivery_report=True,  # optional property
        tag="custom-tag")  # optional property
except Exception as ex:
    print('Exception:')
    print(ex)
Пример #15
0
def cf_communication_sms(cli_ctx, kwargs):
    from azure.communication.sms import SmsClient
    connection_string = kwargs.pop('connection_string', None)
    client = SmsClient.from_connection_string(connection_string)
    return client