Email notification after each survey submitted.

1215
3
10-22-2023 09:03 PM
JinMa2
by
New Contributor II

I created a public survey using Survey 123, now my manager wants to get email notification whenever a survey is submitted.  I understand can set up webhook using Power Automate or Make (formerly Integromat), but we don't have a Microsoft 365 subscription, so Power Automate isn't an option, and we lack a G workplace account, preventing the use of Make. I am stuck... Can anyone provide assistance? Is there a script, whether in Python, Java, or any other language, that can handle this workflow? Any help would be greatly appreciated.

0 Kudos
3 Replies
rsun_TQB
Occasional Contributor III

Hi @JinMa2 ,

Here is what I found using Bing Chat Enterprise for you: 

Sure, you can handle webhooks from Survey123 using Python on a local machine. Here’s a general approach:

  1. Set up a local server: You can use a Python framework like Flask or Django to set up a local server that can listen for incoming HTTP requests.

  2. Create an endpoint for the webhook: In your Python application, create an endpoint that Survey123 will call when a survey is submitted. This endpoint should be capable of handling POST requests, as webhooks typically send data via POST.

  3. Parse the incoming data: When your endpoint receives a request, it will come with a payload containing the data from Survey123. You’ll need to parse this data from the request to use it in your application.

  4. Process the data: Once you’ve parsed the data, you can process it as needed by your application.

Here’s a simple example using Flask:

from flask import Flask, request

app = Flask(__name__)

@app.route('/webhook', methods=['POST'])
def handle_webhook():
data = request.get_json()
print(data)
# Process the data here
return '', 200

if __name__ == '__main__':
app.run(port=5000)

 
Hope this is what you need, but I honestly will recommend Power Automate still...worth the money 🙂 Also, Survey123 community has more people understanding the use and tricks between S123 and Power Automate...so you can find help that you need easily in the long run.
 
You will need a hosted cloud service/server to host your "python" webhook program. If you have FME Cloud or FME Server, you might be able to use it to handle S123 webhook and send out email easily as well. However, everything cames with cost right?
 
 
Cheers!
Reno
0 Kudos
MobiusSnake
MVP

Webhooks are probably the best approach for this type of thing, but an alternative would be to use a ArcGIS Online Notebook that scans your service for new emails at intervals using Python, for example every 15 minutes or every 30 minutes.

You'd want to create a feature service that has a table where you keep the last known count of surveys.  When the script runs, check your current count against the old count and send an email that indicates how many new surveys have been submitted.  After doing so, update your table's count.

If you'll be deleting surveys, you'll want to enable edit tracking, store a "last checked" timestamp rather than a count, and scan for records that are newer than your last timestamp.

As an alternative to a single email, you could send one email for each new record you find.

The main downside of this approach is the delay between submission and notification, however the delay will be at most 15 minutes, if that's how you configure your notebook.

SMauri
by
Occasional Contributor III

Hi @JinMa2,

Here is what Ismael Chivite write in 2018 about this topic: A simple e-mail notification system for Survey123 ... - Esri CommunityP

...probably much more authoritative than Bing Chat Enterprise 😊

Cheers

 

Stefano