Introduction

Continuing our discussion on image extraction using Azure OCR and cross-checking it with the Excel database, we will now utilize Azure Communication Service to send SMS messages. By retrieving the phone number from the Excel sheet, we can initiate SMS notifications if the extracted registration number matches the records in the Excel database. This integration with Azure Communication Service enables us to establish seamless communication with individuals based on the data obtained from the cross-checking process.

To maintain a seamless narrative in this use case, it is advisable to review the previous article if you haven’t already, as the content in this article builds upon the concepts and discussions presented earlier. This will facilitate a comprehensive understanding of the entire use case and ensure a coherent progression of ideas. I have also uploaded the source code of this complete use case (combined code of the previous article and this article ) for your reference.

Step 1. Install Azure Communication SMS Package.

pip install azure-communication-sms

Step 2. Import the necessary libraries for accessing Azure Communication Services.

from azure.communication.sms import SmsClient
from azure.core.credentials import AzureKeyCredential

Step 3. Get the corresponding phone number from the Excel file.

phone_number = matching_rows.iloc[0]['Phone Number']
    print("Phone Number:", phone_number)

Step 4. Authenticate to the Azure Communication service using the endpoint URL and subscription key.

key = 'YOUR-KEY'
endpoint = 'YOUR-END-POINT'

Replace 'your-key' and 'your-end-point' with your actual endpoint URL and subscription key obtained from Azure Communication Service.

Step 5. Initialize the SMS client.

credential = AzureKeyCredential(key)
sms_client = SmsClient(endpoint, credential)

Step 6. Compose and send the message.

message = "Hello! This is a test message."
sms_response = sms_client.send(
from_="YOUR_PHONE_NUMBER",
to=[phone_number],
message=message

To get a number to send from Azure Communication Services,

Sending SMS Notifications with Azure Communication Services in Python

Click on the Phone Number option on the left pane of the Azure Communication Services.

Note: For this you need to have pay-as-you-go subscription.

Step 7. Check if the message was sent successfully.

if sms_response.successful:
        print("Message sent successfully!")
    else:
        print("Message sending failed.")

By following these steps, you can retrieve the phone number from the Excel sheet, we can initiate SMS notifications.