forked from open-runtimes/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into send_email_with_mailgun_deno
- Loading branch information
Showing
47 changed files
with
1,819 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# 📱 Validate phone number and get it's country information | ||
|
||
A Dart Cloud Function that figures out country in which a phone number is registered. | ||
|
||
_Example input:_ | ||
|
||
```json | ||
{ | ||
"phoneNumber": "+421957215740" | ||
} | ||
``` | ||
|
||
> Function can also accept phone numbers with spaces, for instance `+421 957 215 740`. | ||
|
||
_Example output:_ | ||
|
||
|
||
```json | ||
{ | ||
"phoneNumber": "+421957215740", | ||
"phonePrefix": "+421", | ||
"countryCode": "SK", | ||
"countryName": "Slovakia" | ||
} | ||
``` | ||
|
||
## 📝 Environment Variables | ||
|
||
List of environment variables used by this cloud function: | ||
|
||
- **APPWRITE_FUNCTION_ENDPOINT** - Endpoint of your Appwrite server | ||
- **APPWRITE_FUNCTION_API_KEY** - Appwrite API Key | ||
- **APPWRITE_FUNCTION_PROJECT_ID** - Appwrite project ID. If running on Appwrite, this variable is provided automatically. | ||
|
||
## 🚀 Deployment | ||
|
||
1. Clone this repository, and enter this function folder: | ||
|
||
``` | ||
$ git clone https://github.com/open-runtimes/examples.git && cd examples | ||
$ cd dart/convert_phone_number_to_country_name | ||
``` | ||
|
||
2. Enter this function folder and build the code: | ||
``` | ||
docker run -e INTERNAL_RUNTIME_ENTRYPOINT=lib/main.dart --rm --interactive --tty --volume $PWD:/usr/code openruntimes/dart:2.16 sh /usr/local/src/build.sh | ||
``` | ||
As a result, a `code.tar.gz` file will be generated. | ||
|
||
3. Start the Open Runtime: | ||
``` | ||
docker run -p 3000:3000 -e INTERNAL_RUNTIME_KEY=secret-key --rm --interactive --tty --volume $PWD/code.tar.gz:/tmp/code.tar.gz:ro openruntimes/dart:2.16 sh /usr/local/src/start.sh | ||
``` | ||
|
||
Your function is now listening on port `3000`, and you can execute it by sending `POST` request with appropriate authorization headers. To learn more about runtime, you can visit Dart runtime [README](https://github.com/open-runtimes/open-runtimes/tree/main/runtimes/dart-2.16). | ||
|
||
## 📝 Notes | ||
- This function is designed for use with Appwrite Cloud Functions. You can learn more about it in [Appwrite docs](https://appwrite.io/docs/functions). | ||
- This example is compatible with Dart 2.16. Other versions may work but are not guaranteed to work as they haven't been tested. Versions below Dart 2.14 will not work, because Apwrite SDK requires Dart 2.14, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import 'dart:convert'; | ||
import 'dart:io'; | ||
import 'package:dart_appwrite/dart_appwrite.dart'; | ||
|
||
/* | ||
Globally scoped cache used by function. Example value: | ||
[ | ||
{ | ||
"code": "+1", | ||
"countryCode": "US", | ||
"countryName": "United States" | ||
} | ||
] | ||
*/ | ||
var phonePrefixList = null; | ||
|
||
Future<void> start(final req, final res) async { | ||
// Input validation | ||
var phoneNumber = ""; | ||
try { | ||
final payload = jsonDecode(req.payload); | ||
phoneNumber = payload['phoneNumber'].replaceAll(' ', ''); | ||
} catch(err) { | ||
print(err); | ||
throw Exception('Payload is invalid.'); | ||
} | ||
|
||
if(phoneNumber == null || !phoneNumber.startsWith('+')) { | ||
throw Exception('Invalid phone number.'); | ||
} | ||
|
||
// Make sure we have envirnment variables required to execute | ||
if( | ||
req.env['APPWRITE_FUNCTION_ENDPOINT'] == null || | ||
req.env['APPWRITE_FUNCTION_PROJECT_ID'] == null || | ||
req.env['APPWRITE_FUNCTION_API_KEY'] == null | ||
) { | ||
throw Exception('Please provide all required environment variables.'); | ||
} | ||
|
||
// If we don't have cached list of phone number prefixes (first execution only) | ||
if(phonePrefixList == null) { | ||
// Init Appwrite SDK | ||
final client = new Client(); | ||
final locale = new Locale(client); | ||
|
||
client | ||
.setEndpoint(req.env['APPWRITE_FUNCTION_ENDPOINT'] ?? '') | ||
.setProject(req.env['APPWRITE_FUNCTION_PROJECT_ID'] ?? '') | ||
.setKey(req.env['APPWRITE_FUNCTION_API_KEY'] ?? ''); | ||
|
||
// Fetch and store phone number prefixes | ||
final serverResponse = await locale.getCountriesPhones(); | ||
phonePrefixList = serverResponse.phones; | ||
} | ||
|
||
// Get phone prefix | ||
final phonePrefix = phonePrefixList.firstWhere((prefix) => phoneNumber.startsWith(prefix.code)); | ||
|
||
if(phonePrefix == null) { | ||
throw Exception('Invalid phone number.'); | ||
} | ||
|
||
// Return phone number prefix | ||
res.json({ | ||
'phoneNumber': phoneNumber, | ||
'phonePrefix': phonePrefix.code, | ||
'countryCode': phonePrefix.countryCode, | ||
'countryName': phonePrefix.countryName | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
name: convert_phone_number_to_country_name | ||
description: "" | ||
version: 1.0.0 | ||
|
||
environment: | ||
sdk: '>=2.14.0 <3.0.0' | ||
|
||
dependencies: | ||
dart_appwrite: ^4.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# 🖼️ Get Giphy GIF | ||
|
||
A Dart Cloud Function for generating Giphy GIF from the [Giphy API](https://developers.giphy.com/docs/api#quick-start-guide). | ||
|
||
_Example input:_ | ||
|
||
```json | ||
{ | ||
"search": "good morning" | ||
} | ||
``` | ||
|
||
_Example output:_ | ||
|
||
|
||
```json | ||
{ | ||
"search": "good morning", | ||
"gif": "https://giphy.com/gifs/text-gif-sticker-brittdoesdesign-MS9Yq6Y718CSiDTxR5" | ||
} | ||
``` | ||
|
||
## 📝 Environment Variables | ||
|
||
List of environment variables used by this cloud function: | ||
|
||
**GIPHY_API_KEY** - Your Giphy API key. | ||
|
||
## 🚀 Deployment | ||
|
||
1. Clone this repository, and enter this function folder: | ||
|
||
``` | ||
$ git clone https://github.com/open-runtimes/examples.git && cd examples | ||
$ cd dart/generate_giphy_gif | ||
``` | ||
|
||
2. Enter this function folder and build the code: | ||
``` | ||
docker run -e INTERNAL_RUNTIME_ENTRYPOINT=lib/main.dart --rm --interactive --tty --volume $PWD:/usr/code openruntimes/dart:2.16 sh /usr/local/src/build.sh | ||
``` | ||
As a result, a `code.tar.gz` file will be generated. | ||
|
||
3. Start the Open Runtime: | ||
``` | ||
docker run -p 3000:3000 -e INTERNAL_RUNTIME_KEY=secret-key --rm --interactive --tty --volume $PWD/code.tar.gz:/tmp/code.tar.gz:ro openruntimes/dart:2.16 sh /usr/local/src/start.sh | ||
``` | ||
|
||
Your function is now listening on port `3000`, and you can execute it by sending `POST` request with appropriate authorization headers. To learn more about runtime, you can visit Dart runtime [README](https://github.com/open-runtimes/open-runtimes/tree/main/runtimes/dart-2.16). | ||
|
||
## 📝 Notes | ||
- This function is designed for use with Appwrite Cloud Functions. You can learn more about it in [Appwrite docs](https://appwrite.io/docs/functions). | ||
- This example is compatible with Dart 2.16. Other versions may work but are not guaranteed to work as they haven't been tested. Versions below Dart 2.14 will not work, because Apwrite SDK requires Dart 2.14, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import 'dart:convert'; | ||
import 'dart:io'; | ||
import 'package:http/http.dart' as http; | ||
|
||
Future<void> start(final req, final res) async { | ||
final APIKey = req.env["GIPHY_API_KEY"]; | ||
|
||
Map<String, dynamic> data = jsonDecode(req.payload); | ||
|
||
if (!data.containsKey("search")) { | ||
throw new Exception("Missing Search Query"); | ||
} | ||
|
||
if (req.env['GIPHY_API_KEY'] == null) { | ||
throw new Exception("Missing Giphy API Key in environment variables"); | ||
} | ||
|
||
final search = data["search"]; | ||
|
||
// Download image into buffer | ||
var parsedUrl = Uri.parse("https://api.giphy.com/v1/gifs/search?api_key=${APIKey}&q=${search}&limit=1"); | ||
var response = await http.get(parsedUrl); | ||
|
||
if (response.statusCode != 200) { | ||
throw new Exception("Failed to get GIF"); | ||
} | ||
|
||
// Parse response | ||
Map<String, dynamic> parsedBody = jsonDecode(response.body); | ||
|
||
Map<String, dynamic> result = { | ||
"search": search, | ||
"url": parsedBody["data"][0]['url'] | ||
}; | ||
|
||
res.json(result); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
name: object_detection | ||
description: "" | ||
version: 1.0.0 | ||
|
||
environment: | ||
sdk: '>=2.14.0 <3.0.0' | ||
|
||
dependencies: | ||
http: ^0.13.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# 📷 Object Detection using Cloudmersive Vision API | ||
|
||
A Dart Cloud Function for object detection from an image URL. | ||
|
||
_Example input:_ | ||
|
||
```json | ||
{ | ||
"url": "https://picsum.photos/seed/open___runtimes/1000/1000" | ||
} | ||
``` | ||
|
||
_Example output:_ | ||
|
||
|
||
```json | ||
{ | ||
"url": "https://picsum.photos/seed/open___runtimes/1000/1000", | ||
"name": "cake", | ||
"confidence": 0.7977721691131592, | ||
"x": 21, | ||
"y": 5, | ||
"width": 494, | ||
"height": 333 | ||
} | ||
``` | ||
|
||
## 📝 Environment Variables | ||
|
||
List of environment variables used by this cloud function: | ||
|
||
**CLOUDMERSIVE_API_KEY** - Your Cloudmersive API key. | ||
|
||
## 🚀 Deployment | ||
|
||
1. Clone this repository, and enter this function folder: | ||
|
||
``` | ||
$ git clone https://github.com/open-runtimes/examples.git && cd examples | ||
$ cd dart/object_detection | ||
``` | ||
|
||
2. Enter this function folder and build the code: | ||
``` | ||
docker run -e INTERNAL_RUNTIME_ENTRYPOINT=lib/main.dart --rm --interactive --tty --volume $PWD:/usr/code openruntimes/dart:2.16 sh /usr/local/src/build.sh | ||
``` | ||
As a result, a `code.tar.gz` file will be generated. | ||
|
||
3. Start the Open Runtime: | ||
``` | ||
docker run -p 3000:3000 -e INTERNAL_RUNTIME_KEY=secret-key --rm --interactive --tty --volume $PWD/code.tar.gz:/tmp/code.tar.gz:ro openruntimes/dart:2.16 sh /usr/local/src/start.sh | ||
``` | ||
|
||
Your function is now listening on port `3000`, and you can execute it by sending `POST` request with appropriate authorization headers. To learn more about runtime, you can visit Dart runtime [README](https://github.com/open-runtimes/open-runtimes/tree/main/runtimes/dart-2.16). | ||
|
||
## 📝 Notes | ||
- This function is designed for use with Appwrite Cloud Functions. You can learn more about it in [Appwrite docs](https://appwrite.io/docs/functions). | ||
- This example is compatible with Dart 2.16. Other versions may work but are not guaranteed to work as they haven't been tested. Versions below Dart 2.14 will not work, because Apwrite SDK requires Dart 2.14, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import 'dart:convert'; | ||
import 'dart:io'; | ||
import 'package:http/http.dart' as http; | ||
|
||
Future<void> start(final req, final res) async { | ||
final APIKey = req.env["CLOUDMERSIVE_API_KEY"]; | ||
|
||
Map<String, dynamic> data = jsonDecode(req.payload); | ||
|
||
if (!data.containsKey("url")) { | ||
throw new Exception("Missing url"); | ||
} | ||
|
||
if (req.env['CLOUDMERSIVE_API_KEY'] == null) { | ||
throw new Exception("Missing Cloudmersive API Key in environment variables"); | ||
} | ||
|
||
final url = data["url"]; | ||
|
||
// Download image into buffer | ||
var parsedUrl = Uri.parse(url); | ||
var response = await http.get(parsedUrl); | ||
|
||
if (response.statusCode != 200) { | ||
throw new Exception("Failed to download image"); | ||
} | ||
|
||
var imageBuffer = response.bodyBytes; | ||
|
||
var request = new http.MultipartRequest('POST', Uri.parse("https://api.cloudmersive.com/image/recognize/detect-objects")) | ||
..files.add(new http.MultipartFile.fromBytes('imageFile', imageBuffer)) | ||
..headers['Apikey'] = APIKey; | ||
|
||
// Call Cloudmersive OCR API | ||
var cloudmersiveResponse = await request.send(); | ||
|
||
// Parse response | ||
var responseBody = await cloudmersiveResponse.stream.bytesToString(); | ||
Map<String, dynamic> parsedBody = jsonDecode(responseBody); | ||
|
||
if (parsedBody["Objects"] == null) { | ||
throw new Exception("No objects detected"); | ||
} | ||
|
||
res.json(parsedBody["Objects"][0]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
name: object_detection | ||
description: "" | ||
version: 1.0.0 | ||
|
||
environment: | ||
sdk: '>=2.14.0 <3.0.0' | ||
|
||
dependencies: | ||
http: ^0.13.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
Oops, something went wrong.