Select to view content in your preferred language

Assigning Survey123 Spills to Workforce Responders - Need Guidance

361
11
11-19-2024 08:49 AM
ChallagundlaSindhuraITS
Emerging Contributor

Hi,
I need help with a Python script requirement.

The setup:

  • A Survey123 form collects spill data in one feature layer.
  • A Workforce app stores responder details (phone, email, region) in another feature layer.

    The task:
    I need to write a script to:

    1. Assign spills from the Survey123 form to responders based on their region.
    2. Send email or text notifications to the assigned responders as soon as a spill is created.

      What I’ve tried:

      • Created a script to access and join the feature layers on the county field.
      • Attempted to send emails using smtplib, but I ran into connection issues on my local machine.

        Questions:

        • How can I reliably send the notifications (email/text)?
        • Where should I host the script to make it run automatically when new spills are added?

          Any advice or ideas are appreciated!

0 Kudos
11 Replies
JakeSkinner
Esri Esteemed Contributor

@ChallagundlaSindhuraITS is your Survey123 feature service hosted in AGOL?  Here is an example script on how to send an e-mail for an AGOL hosted feature service:

https://community.esri.com/t5/python-documents/send-email-when-a-feature-is-added-to-an-arcgis/ta-p/...

I recommend configuring Windows Task Scheduler to execute this script on a server that has ArcGIS Pro install, and will not be turned off.

0 Kudos
ChallagundlaSindhuraITS
Emerging Contributor

Thank You @JakeSkinner  for a quick reply!!

Yes, the Survey123 form developed by user is in AGOL. The data is in AGOL. I access the data from the feature layer using a API call.

I will try the script you have suggested for emails. The .py script i write cannot be hosted on my side. Is hosting the .py script on esri cloud possible? i am asking since the script uses two feature layers developed by the user and nothing related to the application on my side.

0 Kudos
JakeSkinner
Esri Esteemed Contributor

@ChallagundlaSindhuraITS yes, you can use AGOL Notebooks to host the script.  Below is an example on how to send an e-mail.

from arcgis.gis import GIS

# Variables
username = 'jskinner_rats'
password = '********'

# Connect to AGOL
gis = GIS('https://www.arcgis.com', username, password)

# Create list of users to send e-mail to
userList = []
user = gis.users.get('jskinner_rats')
userList.append(user)

# Construct message and send
messageSubject = 'This is a test message from AGOL'
messageMessage = 'This is the plain text message that we are sending.'
gis.users.send_notification(userList, subject = messageSubject, message = messageMessage, type = 'email')

 

ChallagundlaSindhuraITS
Emerging Contributor

Hi @JakeSkinner ,

I have tried this code snippet , but the account i use to connect to doesnt have permissions. Error: You do not have permissions to access this resource or perform this operation.
(Error Code: 403)

gis = GIS('https://www.arcgis.com', username, password)

Do you have any suggestions to send emails using smtplib?

 

 

 

0 Kudos
JakeSkinner
Esri Esteemed Contributor

Unfortunately, you won't be able to send an e-mail using smtplib in AGOL Notebooks.  

0 Kudos
ChallagundlaSindhuraITS
Emerging Contributor

Hi @JakeSkinner , I can't go the route of using gis.users.send_notification becasue the account i use to connect to arcgis and send emails wont get the admin rights.

0 Kudos
ChallagundlaSindhuraITS
Emerging Contributor

Thank You JakeSkinner, Is it possible to send emails from AGOL notebooks to the out of organisation emails(not GIS users)? Also can we send text messages to the phonenumbers from AGOL notebooks? Please advice. Thanks again

0 Kudos
JakeSkinner
Esri Esteemed Contributor

I would recommend using a local server that has ArcGIS Pro to execute your scripts.  You can then leverage the smtplib module and send e-mails/texts.

0 Kudos
ChallagundlaSindhuraITS
Emerging Contributor

Thank You JakeSkinner , I dont have ArcGIS Pro software, Is there a way i can do with Arcgis API for Python to send emails/texts?

0 Kudos