This is an automated email from the ASF dual-hosted git repository.

bsalzano pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/openserverless-tutorial.git

commit bad3177d83a0c601f060791ddab058a05d5b4d08
Author: Bruno Salzano <[email protected]>
AuthorDate: Sat Mar 22 19:29:24 2025 +0100

    notify-message
---
 packages/.env.example      |  1 +
 packages/contact/notify.js | 57 ++++++++++++++++++++++++++++++++++++++++++++++
 web/index.html             |  2 +-
 3 files changed, 59 insertions(+), 1 deletion(-)

diff --git a/packages/.env.example b/packages/.env.example
new file mode 100644
index 0000000..325436a
--- /dev/null
+++ b/packages/.env.example
@@ -0,0 +1 @@
+NOTIFICATION_URL=<url here>
\ No newline at end of file
diff --git a/packages/contact/notify.js b/packages/contact/notify.js
new file mode 100644
index 0000000..4aa1b4d
--- /dev/null
+++ b/packages/contact/notify.js
@@ -0,0 +1,57 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//--param NOTIFICATION_URL $NOTIFICATION_URL
+
+function main(args) {
+    const { name, email, phone, message } = args;
+
+    const subject = `New contact request from Apache OpenServerless`;
+    const payload = {
+        subject,
+        name,
+        email,
+        phone,
+        message,
+    };
+
+    console.log("Built message", payload);
+
+    return fetch(args.NOTIFICATION_URL, {
+        method: 'POST',
+        headers: {
+            'Content-Type': 'application/json',
+        },
+        body: JSON.stringify(payload),
+    })
+        .then(response => {
+            if (!response.ok) {
+                console.log("Error sending message. Status code:", 
response.status);
+            } else {
+                console.log("Message sent successfully");
+            }
+            return {
+                body: args.body,
+            };
+        })
+        .catch(error => {
+            console.log("Error sending message", error);
+            return {
+                body: error,
+            };
+        });
+}
diff --git a/web/index.html b/web/index.html
index 2521b40..ba86be7 100644
--- a/web/index.html
+++ b/web/index.html
@@ -33,7 +33,7 @@
     <div class="w-50 p-4 border rounded bg-light shadow">
         <h2 class="text-center mb-4">Get In Touch</h2>
         
-        <form method="POST" 
action="/api/v1/web/opstutorial/contact/submit-write" 
enctype="application/x-www-form-urlencoded">
+        <form method="POST" 
action="/api/v1/web/opstutorial/contact/submit-notify" 
enctype="application/x-www-form-urlencoded">
             <div class="mb-3">
                 <label for="name" class="form-label">Name</label>
                 <input type="text" class="form-control" id="name" name="name" 
placeholder="Insert your name">

Reply via email to