Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat 3960 kotlin send message function #157

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
050b01a
Added sendMessage in Kotlin folder
softTam Jun 30, 2023
d396222
Added function headers to Index.kt file
jamesrcramos Jul 6, 2023
1f00f03
Added main function, no input validator
softTam Jul 6, 2023
ebdbafe
Resolved merge conflict
softTam Jul 6, 2023
af23ab6
Fixed syntax errors; working main and helper fnctions
softTam Jul 6, 2023
a34f702
Added sendMessageDiscordWebhook function
softTam Jul 7, 2023
5d0b5ac
Added unfinished sendEmailMailgun.kt file; troubleshoot authenticatio…
jamesrcramos Jul 7, 2023
815e068
Merged to catch up to codebase
jamesrcramos Jul 7, 2023
7a60348
Added sendMessageSMS kotlin file; in progress
ArtP1 Jul 8, 2023
cbc5ec5
Added sendMessageTwitter kotlin file; in progress
ArtP1 Jul 8, 2023
a99371c
Completed sendMessageSMS & error handling on main
ArtP1 Jul 10, 2023
51fdeb1
Created working version of Mailgun implementation
jamesrcramos Jul 10, 2023
c3feaff
Improved function formatting and return statements
jamesrcramos Jul 11, 2023
c5e7e39
Draft. Commit for the purpose of pulling from origin
softTam Jul 11, 2023
816c20e
Merge branch 'feat-3960-kotlin-sendMessage-function' of https://githu…
softTam Jul 11, 2023
94ba8bd
Moved sendEmail function to Index.kt and minor syntax improvements an…
jamesrcramos Jul 11, 2023
d4dca46
Added sendTweet. Got 401 - Unauthorized error.
softTam Jul 12, 2023
301e757
Combined all functions into Index.kt. Deleted all helper files.
softTam Jul 12, 2023
6818141
Deleted all helper files.
softTam Jul 12, 2023
b535124
Removed messages from return statements
jamesrcramos Jul 12, 2023
5344941
Added READ.me file
ArtP1 Jul 12, 2023
d83e346
Suncessfully implemented sendTweet() function
softTam Jul 12, 2023
83b360c
Added input validation for sendTweet. Cleaned up comments.
softTam Jul 12, 2023
59e13fd
Updated README.md file with Twitter option.
softTam Jul 12, 2023
562a787
Added more input validation. Ensured consistency in stylyes. Moved In…
softTam Jul 13, 2023
5fdca32
Fixed READ.me file
ArtP1 Jul 13, 2023
57c23b1
Fix: wrong path declared in READ.me file
ArtP1 Jul 13, 2023
0e251e1
Minimized the number of newlines
ArtP1 Jul 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
186 changes: 186 additions & 0 deletions kotlin/sendMessage/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@

# SendMessage()

A Kotlin Cloud Function for sending a message using a specific channel to a receiver



Supported channels are `SMS`, `Email` , `Disocrd`, and `Twitter`.



_SMS Example payload_



```json
{
"type": "SMS",
"receiver": "+123456789",
"message": "Programming is fun!"
}
```



_Email Example payload_



```json
{
"type": "Email",
"receiver": "[email protected]",
"message": "Programming is fun!",
"subject": "Programming is funny!"
}
```



_Discord Example payload_



```json

{
"type": "Discord",
"message": "Hi"
}
```

_Twitter Example payload_



```json
{
"type": "Twitter",
"message": "Programming is fun!"
}
```



_Successful function response:_



```json
{
"success": true
}
```



_Error function response:_



```json
{
"success": false,
"message": "Failed to send message,check webhook URL"
}
```

## 📝 Variables



List of variables used by this cloud function:



Mailgun



- **MAILGUN_API_KEY** - API Key for Mailgun
- **MAILGUN_DOMAIN** - Domain Name from Mailgun



Discord



- **DISCORD_WEBHOOK_URL** - Webhook URL for Discord



Twilio



- **TWILIO_ACCOUNT_SID** - Acount SID from Twilio
- **TWILIO_AUTH_TOKEN** - Auth Token from Twilio
- **TWILIO_SENDER** - Sender Phone Number from Twilio

Twitter
- **TWITTER_API_KEY** - API Key for Twitter
- **TWITTER_API_KEY_SECRET** - API Key Secret for Twitter
- **TWITTER_ACCESS_TOKEN** - Access Token from Twitter
- **TWITTER_ACCESS_TOKEN_SECRET** - Access Token Secret from Twitter


## 🚀 Deployment



1. Clone this repository, and enter this function folder:



```
$ git clone https://github.com/open-runtimes/examples.git && cd examples
$ cd kotlin/sendMessage
```



2. Enter this function folder and build the code:



```bash
docker run -e INTERNAL_RUNTIME_ENTRYPOINT=src/Index.kt --rm --interactive --tty --volume $PWD:/usr/code openruntimes/kotlin:v2-1.6 sh /usr/local/src/build.sh
```



As a result, a `code.tar.gz` file will be generated.



3. Spin-up open-runtime:



```bash
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/kotlin:v2-1.6 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 Kotlin runtime [README](https://github.com/open-runtimes/open-runtimes/tree/main/runtimes/kotlin-1.6/example).



4. In new terminal window, execute the function. Example curl command (Email):



```bash
curl -X POST http://localhost:3000/ -d '{"variables": {"MAILGUN_API_KEY":"YOUR_MAILGUN_API_KEY","MAILGUN_DOMAIN":"YOUR_MAILGUN_DOMAIN"},"payload": "{\"type\": \"Email\",\"receiver\": \"[email protected]\",\"message\": \"Programming is fun!\",\"subject\": \"Programming is funny!\"}"}' -H "X-Internal-Challenge: secret-key" -H "Content-Type: application/json"
```



## 📝 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).
4 changes: 4 additions & 0 deletions kotlin/sendMessage/deps.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dependencies {
implementation 'com.google.code.gson:gson:2.9.0'
implementation 'com.chromasgaming:ktweet:1.3.0'
}
Loading