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: add 2 function template blogs #345

Merged
merged 2 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
layout: post
title: Build An Intelligent Chatbot With ChatGPT And Appwrite Functions
description: Learn how to use an Appwrite Function Template to create an interactive bot using GPT-3.5.
date: 2023-11-15
cover: /images/blog/function-template-prompt-chatgpt/cover.png
timeToRead: 5
author: aditya-oberai
category: functions
---

Function templates are pre-built Appwrite Functions that can be integrated into your Appwrite project with just a few clicks. Using them, you can easily incorporate new features and integrations into your app without writing additional code or managing infrastructure.

One such integration you can implement using Appwrite Functions is an **intelligent chatbot** using **ChatGPT**. In this blog, you will learn how you can use an Appwrite Function Template to create an interactive bot that will answer any of your questions using OpenAI’s GPT-3.5 API.

## Setting up the OpenAI Platform

To get an OpenAI API Key, you must create an account on the [OpenAI platform](https://platform.openai.com/). Once your account is set up, visit their [API keys](https://platform.openai.com/account/api-keys) page and create an **API Key**. Ensure you copy and save this key in a safe place, as the OpenAI platform will not let you view the key after it is created.

![OpenAI Platform](/images/blog/function-template-prompt-chatgpt/openai-api-keys.png)

## Preparing the Appwrite Function

Now that we have our OpenAI API Key, let us get the function ready on **[Appwrite](https://cloud.appwrite.io)**. Head over to your Appwrite project and visit the **Functions** page. From there, we will select the **Templates** tab, search for and select the **Prompt ChatGPT** function template.

![Function Templates](/images/blog/function-template-prompt-chatgpt/templates.png)

This function requires **1 environment variable** to setup:

- `OPENAI_API_KEY`: API Key from our OpenAI account

After you have configured the environment variables, you must connect your Appwrite account with GitHub, select **Create a new repository** (this will generate a GitHub repository for you with the function), and leave the production branch and root settings as default to create this function.

Once the function is ready, visit the **Domains** tab on the function page and copy the domain URL to test the function.

![Function Domain](/images/blog/function-template-prompt-chatgpt/domains.png)

## Testing the Function

Once all the aforementioned steps are complete, it is time to test the function!

To consume this function, you must send the function URL a `POST` HTTP Request with a **JSON Body** in the following format:

```json
{
"prompt": "<ENTER YOUR PROMPT>"
}
```

If successful, you will receive a response in the following format:

```json
{
"ok": true,
"completion": "<CHAT COMPLETION FROM GPT-3.5>"
}
```

Here’s a screenshot of a test prompt that was sent to the function using Postman:

![Postman](/images/blog/function-template-prompt-chatgpt/postman.png)

## Next Steps

We’ve covered the basics, and now it’s your time to shine! With a few changes, you should be able to extend this template to fit your app. Be sure to check out the other available Function Templates. We’ve created many that could be of use in your projects. You can find the [templates GitHub repository here](https://github.com/appwrite/templates).

For more information about Appwrite and Appwrite Functions:

- [Appwrite Function Docs](https://appwrite.io/docs/functions): These documents provide more information on how to use Appwrite Functions.
- [Functions Announcement](https://dev.to/appwrite/serverless-your-way-unleashing-appwrite-functions-true-potential-2l4f): Read the full announcement on Functions 1.4.
- [Appwrite Discord](https://discord.com/invite/appwrite): Connect with other developers and the Appwrite team for discussion, questions, and collaboration.
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
layout: post
title: Send WhatsApp Messages With Vonage And Appwrite Functions
description: Learn how to use an Appwrite Function Template to create a Whatsapp bot that will programmatically respond to incoming WhatsApp messages via Vonage.
date: 2023-11-15
cover: /images/blog/function-template-whatsapp-vonage/cover.png
timeToRead: 5
author: aditya-oberai
category: functions
---

Function templates are pre-built Appwrite Functions that can be integrated into your Appwrite project with just a few clicks. Using them, you can easily incorporate new features and integrations into your app without writing additional code or managing infrastructure.

One such integration you can implement using Appwrite Functions is **WhatsApp messaging** via **Vonage**. In this blog, you will learn how you can use an Appwrite Function Template to create a Whatsapp bot that will programmatically respond to incoming WhatsApp messages via Vonage.


## Setting up Vonage

The first step is to create a Vonage account. Head over to Vonage’s [website](https://www.vonage.com/) and [sign up](https://dashboard.nexmo.com/sign-up?icid=tryitfree_homepage_nexmodashbdfreetrialsignup_tile&utm_campaign=bizdirect&attribution_campaign=bizdirect&cjregion=429207&adobe_mc=MCMID%3D34270386780739068404296704713035591008%7CMCORGID%3DA8833BC75245AF9E0A490D4D%2540AdobeOrg%7CTS%3D1663266957) to use Vonage Communication APIs. On the Vonage API Dashboard, visit the **[API Settings](https://dashboard.nexmo.com/settings)** tab and copy the **API Key**, **API Secret**, and **Signature Secret** from there.

![Vonage API Dashboard](/images/blog/function-template-whatsapp-vonage/api-settings.png)

After that, visit the **[Messages API Sandbox](https://dashboard.nexmo.com/messages/sandbox)** and enable **WhatsApp** to set up a test environment for our Appwrite Function template. Make sure to copy the **Phone Number** provided there (and join the WhatsApp channel with the instructions on the page. Once the Appwrite Function is deployed, we will return here to add the Function URL as the **Inbound Webhook** link.

![Vonage Messages API Sandbox](/images/blog/function-template-whatsapp-vonage/messages-sandbox.png)

## Preparing the Appwrite Function

Now that we have all the necessary details from our Vonage account, let us get the function ready on **[Appwrite](https://cloud.appwrite.io)**. Head over to your Appwrite project and visit the **Functions** page. From there, we will select the **Templates** tab, search for and select the **WhatsApp with Vonage** function template.

![Functions Templates](/images/blog/function-template-whatsapp-vonage/templates.png)

This function requires **4 environment variables** to setup:

- `VONAGE_API_KEY`: API Key from our Vonage account *(copied from the API Settings)*
- `VONAGE_API_SECRET`: API Secret from our Vonage account *(copied from the API Settings)*
- `VONAGE_API_SIGNATURE_SECRET`: Secret used to sign and verify the JWT token sent by Vonage *(copied from the API Settings)*
- `VONAGE_WHATSAPP_NUMBER`: Vonage WhatsApp number to send messages from *(copied from the Messages API Sandbox)*

After you have configured the environment variables, you must connect your Appwrite account with GitHub, select **Create a new repository** (this will generate a GitHub repository for you with the function), and leave the production branch and root settings as default to create this function.

Once the function is ready, visit the **Domains** tab on the function page and copy the domain to add to the **Inbound Webhook** link on the **Messages API Sandbox** page on your Vonage account.

![Function Domain](/images/blog/function-template-whatsapp-vonage/domains.png)

## Testing the Function

Once all the aforementioned steps are complete, it is time to test the function!

Open the WhatsApp app on your phone, join the Vonage WhatsApp Channel (via the steps mentioned on the *Messaging API Sandbox* on *Vonage*), and send any message to the WhatsApp number. You shall receive a message in the format: `Hi there! You sent me: <SENT MESSAGE>`

![WhatsApp](/images/blog/function-template-whatsapp-vonage/whatsapp.png)

## Next Steps

We’ve covered the basics, and now it’s your time to shine! With a few changes, you should be able to extend this template to fit your app. Be sure to check out the other available Function Templates. We’ve created many that could be of use in your projects. You can find the [templates GitHub repository here](https://github.com/appwrite/templates).

For more information about Appwrite and Appwrite Functions:

- [Appwrite Function Docs](https://appwrite.io/docs/functions): These documents provide more information on how to use Appwrite Functions.
- [Functions Announcement](https://dev.to/appwrite/serverless-your-way-unleashing-appwrite-functions-true-potential-2l4f): Read the full announcement on Functions 1.4.
- [Appwrite Discord](https://discord.com/invite/appwrite): Connect with other developers and the Appwrite team for discussion, questions, and collaboration.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.