Skip to content

Commit

Permalink
Merge pull request #7 from adityaoberai/remove-appwrite-api-key
Browse files Browse the repository at this point in the history
Remove Appwrite API key
  • Loading branch information
adityaoberai authored Feb 9, 2023
2 parents 7bbffb6 + da84e53 commit 83cad76
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ https://user-images.githubusercontent.com/31401437/214066632-527eb619-b7f4-44e3-

* [Setup an Appwrite instance](https://appwrite.io/docs/installation), create a new admin account and a new project
* Enable the **.NET 6.0 runtime for Appwrite Functions** (check the note below)
* Create an API Key with the `execution.write` scope enabled
* [Install the Appwrite CLI](https://appwrite.io/docs/command-line#installation) and login with your Appwrite credentials
* Create an account on [Twilio](https://twilio.com), obtain your Twilio Account SID and Auth Token from your Twilio console, and await a Phone Number (using this [guide](https://support.twilio.com/hc/en-us/articles/223135247-How-to-Search-for-and-Buy-a-Twilio-Phone-Number-from-Console))
* Create an account on [Radar](https://radar.com) and grab an API key (*Test secret(server) should be fine*)
* Visit the SOS Appwrite Function Readme in the [`appwrite-function`](https://github.com/adityaoberai/SOS-MAUI/tree/appwrite-function) branch for more details on setting up and deploying the function
* Visit the SOS Function's Settings page and add **Execute Access** for `any` role

> Note: In order to enable the .NET runtime for Appwrite Functions, you need to update the `.env` file in the Appwrite installation folder. Find the file and add `dotnet-6.0` to the comma-separated list in the environment variable `_APP_FUNCTIONS_RUNTIMES`. This will make the .NET runtime available in Appwrite Functions. You can then load the updated configuration using the `docker-compose up -d` command.
Expand All @@ -45,10 +45,9 @@ https://user-images.githubusercontent.com/31401437/214066632-527eb619-b7f4-44e3-
{
public static class AppwriteConstants
{
public const string AppwriteUrl = "<Enter URL of Appwrite instance>"; // Enter just the URL without the functions endpoint (e.g.: https://appwrite.oberai.dev or http://localhost)
public const string AppwriteUrl = "<Enter Appwrite API Endpoint>";
public const string ProjectId = "<Enter Appwrite Project Id>";
public const string FunctionId = "<Enter Appwrite Function Id>";
public const string ApiKey = "<Enter Appwrite API Key>";
}
}
```
Expand Down
7 changes: 3 additions & 4 deletions SOS/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,12 @@ private async void SOSButtonClicked(object sender, EventArgs e)
}
else
{
var endpoint = $"/v1/functions/{AppwriteConstants.FunctionId}/executions";
var endpoint = $"/functions/{AppwriteConstants.FunctionId}/executions";
var uri = new Uri(AppwriteConstants.AppwriteUrl + endpoint);

HttpClient client = new HttpClient();
client.BaseAddress = new Uri(AppwriteConstants.AppwriteUrl);
client.DefaultRequestHeaders.Add("X-Appwrite-Response-Format", "1.0.0");
client.DefaultRequestHeaders.Add("X-Appwrite-Project", AppwriteConstants.ProjectId);
client.DefaultRequestHeaders.Add("X-Appwrite-Key", AppwriteConstants.ApiKey);

Dictionary<string, string> requestData = new Dictionary<string, string>();
requestData.Add("phoneNumber", settings.PhoneNumber);
Expand All @@ -75,7 +74,7 @@ private async void SOSButtonClicked(object sender, EventArgs e)
};
var jsonContent = new StringContent(JsonConvert.SerializeObject(appwriteRequestInput), System.Text.Encoding.UTF8, "application/json");

var sosResponse = await client.PostAsync(endpoint, jsonContent);
var sosResponse = await client.PostAsync(uri, jsonContent);
var sosResponseContent = await sosResponse.Content.ReadAsStringAsync();
var sosResponseObject = JsonConvert.DeserializeObject<AppwriteApiResponse>(sosResponseContent); // Complete function response from Appwrite
var sosResponseData = JsonConvert.DeserializeObject<AppwriteResponseData>(sosResponseObject.Response); // Data returned from function
Expand Down

0 comments on commit 83cad76

Please sign in to comment.