Skip to content

Commit

Permalink
Merge pull request #11 from NipunaRanasinghe/package.md
Browse files Browse the repository at this point in the history
Add missing Package.md content
  • Loading branch information
NipunaRanasinghe authored Jul 4, 2024
2 parents 49cd8c7 + e87e68a commit 5543988
Showing 1 changed file with 88 additions and 0 deletions.
88 changes: 88 additions & 0 deletions ballerina/Package.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
## Overview

[Discord](https://support.discord.com/hc/en-us/articles/360045138571-Beginner-s-Guide-to-Discord) is a popular communication platform designed for creating communities and facilitating real-time messaging, voice, and video interactions over the internet.

The Ballerina Discord connector offers APIs to connect and interact with the [Discord REST API v10](https://discord.com/developers/docs/reference).

## Setup guide

Follow these steps to create a Discord developer account.

### Step 1: Login to Discord developer page

<img src="https://github.com/HussainLatiff/module-ballerinax-discord/blob/main/docs/setup/resources/discord-dev-page.png?raw=true">

Visit [Discord developer portal](https://discord.com/login?redirect_to=%2Fdevelopers) by logging into your Discord account.

If you do not have a Discord account already, [create a new discord account](https://discord.com/login) by clicking on the `Register` hyperlink below the `Log In` button when opening the Discord developer page.

<img src= "https://github.com/HussainLatiff/module-ballerinax-discord/blob/main/docs/setup/resources/create-acc.png?raw=true">

Complete the account creation process by including the relavant information in the given fields.

### Step 2: Make a new Discord application

<img src="https://github.com/HussainLatiff/module-ballerinax-discord/blob/main/docs/setup/resources/make-new-app.png?raw=true">

Once in the Discord developer portal is open, click on the `New Application` button as displayed above to start the process.

### Step 3: Name the Discord Application

<img src="https://github.com/HussainLatiff/module-ballerinax-discord/blob/main/docs/setup/resources/create-app.png?raw=true">

1. Proceed by giving the Discord Application a name and click on the terms of service.

2. Finally complete the naming process by clicking on the `next` button.

### Step 4: Obtain the Client ID and Client Secret

<img src="https://github.com/HussainLatiff/module-ballerinax-discord/blob/main/docs/setup/resources/obtain-client-id.png?raw=true">

Under the `OAuth2` section found on the left-sided list, locate the Client's Information as shown on the screen. To implement the functionalities provided by Discord's API, you will need the Client ID and Client Secret.

## Quickstart

To use the `discord` connector in your Ballerina application, modify the `.bal` file as follows:

### Step 1: Import the module

Import the `discord` module.

```ballerina
import ballerinax/discord;
```

### Step 2: Instantiate a new connector

Create a `discord:ConnectionConfig` with the obtained OAuth2.0 Client Credentials and initialize the connector with it.

Apps must receive approval from users installing them to perform actions within Discord. To enable these functions, specific scopes must be defined. These scopes are outlined in the [OAuth2 Scopes documentation](https://discord.com/developers/docs/topics/oauth2#shared-resources-oauth2-scopes).

```ballerina
configurable string clientId = ?;
configurable string clientSecret = ?;
configurable string[] scopes = ?;
discord:Client discord = check new({
auth: {
clientId,
clientSecret,
scopes
}
});
```

### Step 3: Invoke the connector operation
Now, utilize the available connector operations.

### Return linked third-party accounts of the user

```ballerina
ConnectedAccountResponse[] connectedAccounts = check cl->/users/\@me/connections();
````
### Step 4: Run the Ballerina application
```bash
bal run
```

0 comments on commit 5543988

Please sign in to comment.