Skip to content

Commit

Permalink
Merge pull request #159 from adibmbrk/master
Browse files Browse the repository at this point in the history
Add automated summary report as an example
  • Loading branch information
NipunaRanasinghe authored Jul 5, 2024
2 parents 4ec03cc + 89a6a35 commit 0a06fac
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 25 deletions.
25 changes: 16 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,39 +23,39 @@ For more information, go to the modules.

To use the Slack Connector you need to be signed in to [Slack](https://slack.com/).

![Sign In Page](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-slack/master/docs/setup/resources/sign-in.png)
<img src=https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-slack/master/docs/setup/resources/sign-in.png alt="Sign-In Page" style="width: 70%;">

If you haven't created an account already, you can create it [here](https://slack.com/get-started#/createnew).

### Step 1: Create a new Slack application
### Step 1: Create a new Slack application

1. Navigate to your apps in [Slack API](https://api.slack.com/) and create a new Slack app.

![Create Slack App](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-slack/master/docs/setup/resources/create-slack-app.png)
<img src=https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-slack/master/docs/setup/resources/create-slack-app.png alt="Create Slack App" style="width: 70%;">

2. Provide an app name and choose a workspace of your choice.

![Create Slack App Popup](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-slack/master/docs/setup/resources/create-slack-app-2.png)
<img src=https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-slack/master/docs/setup/resources/create-slack-app-2.png alt="Create Slack App Popup" style="width: 70%;">

3. Click on the "Create App" button.

### Step 2: Add scopes to the token
### Step 2: Add scopes to the token

1. Once the application is created, go to the "Add Features and Functionality" section and click on "Permissions" to set the token scopes.

![Add Features and Functionality](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-slack/master/docs/setup/resources/add-features.png)
<img src=https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-slack/master/docs/setup/resources/add-features.png alt="Add features and functionality" style="width: 70%;">

2. In the **User Token Scopes** section set the following token scopes.

![User Token Scopes](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-slack/master/docs/setup/resources/token-permissions.png)
<img src=https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-slack/master/docs/setup/resources/token-permissions.png alt="User Token Scopes" style="width: 70%;">

3. Install the application to workspace.

![Install to workspace ](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-slack/master/docs/setup/resources/install-workspace.jpg)
<img src=https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-slack/master/docs/setup/resources/install-workspace.jpg alt="Install to workspace" style="width: 70%;">

4. Copy the OAuth token that is generated upon installation.

![Copy Token](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-slack/master/docs/setup/resources/copy-token.jpg)
<img src=https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-slack/master/docs/setup/resources/copy-token.jpg alt="Copy token" style="width: 70%;">


## Quickstart
Expand Down Expand Up @@ -100,6 +100,13 @@ json postMessageResponse = check slack->/chat\.postMessage.post({channel: "gener
bal run
```

## Examples

The `Slack` connector provides practical examples illustrating usage in various scenarios. Explore these [examples](https://github.com/ballerina-platform/module-ballerinax-slack/tree/master/examples), covering the following use cases:

1. [Automated Survey Report](https://github.com/ballerina-platform/module-ballerinax-slack/tree/master/examples/automated-survey-report) - This use case demonstrates how the Slack API can be utilized to generate a summarized report of daily stand up chats in the general channel.

2. [Survey Feedback Analysis](https://github.com/ballerina-platform/module-ballerinax-slack/tree/master/examples/survey-feedback-analysis) - This use case demonstrates how the Slack API can be utilized to perform a company-wide survey by creating a dedicated channel to receive and track feedback replies.

## Build from the source

Expand Down
22 changes: 15 additions & 7 deletions ballerina/Module.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,39 @@

To use the Slack Connector you need to be signed in to [Slack](https://slack.com/).

![Sign In Page](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-slack/master/docs/setup/resources/sign-in.png)
<img src=https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-slack/master/docs/setup/resources/sign-in.png alt="Sign-In Page" style="width: 70%;">

If you haven't created an account already, you can create it [here](https://slack.com/get-started#/createnew).

### Step 1: Create a new Slack application

1. Navigate to your apps in [Slack API](https://api.slack.com/) and create a new Slack app.

![Create Slack App](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-slack/master/docs/setup/resources/create-slack-app.png)
<img src=https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-slack/master/docs/setup/resources/create-slack-app.png alt="Create Slack App" style="width: 70%;">

2. Provide an app name and choose a workspace of your choice.

![Create Slack App Popup](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-slack/master/docs/setup/resources/create-slack-app-2.png)
<img src=https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-slack/master/docs/setup/resources/create-slack-app-2.png alt="Create Slack App Popup" style="width: 70%;">

3. Click on the "Create App" button.

### Step 2: Add scopes to the token

1. Once the application is created, go to the "Add Features and Functionality" section and click on "Permissions" to set the token scopes.

![Add Features and Functionality](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-slack/master/docs/setup/resources/add-features.png)
<img src=https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-slack/master/docs/setup/resources/add-features.png alt="Add features and functionality" style="width: 70%;">

2. In the **User Token Scopes** section set the following token scopes.

![User Token Scopes](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-slack/master/docs/setup/resources/token-permissions.png)
<img src=https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-slack/master/docs/setup/resources/token-permissions.png alt="User Token Scopes" style="width: 70%;">

3. Install the application to workspace.

![Install to workspace ](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-slack/master/docs/setup/resources/install-workspace.jpg)
<img src=https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-slack/master/docs/setup/resources/install-workspace.jpg alt="Install to workspace" style="width: 70%;">

4. Copy the OAuth token that is generated upon installation.

![Copy Token](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-slack/master/docs/setup/resources/copy-token.jpg)
<img src=https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-slack/master/docs/setup/resources/copy-token.jpg alt="Copy token" style="width: 70%;">


## Quickstart
Expand Down Expand Up @@ -82,3 +82,11 @@ json postMessageResponse = check slack->/chat\.postMessage.post({channel: "gener
```bash
bal run
```

## Examples

The `Slack` connector provides practical examples illustrating usage in various scenarios. Explore these [examples](https://github.com/ballerina-platform/module-ballerinax-slack/tree/master/examples), covering the following use cases:

1. [Automated Survey Report](https://github.com/ballerina-platform/module-ballerinax-slack/tree/master/examples/automated-survey-report) - This use case demonstrates how the Slack API can be utilized to generate a summarized report of daily stand up chats in the general channel.

2. [Survey Feedback Analysis](https://github.com/ballerina-platform/module-ballerinax-slack/tree/master/examples/survey-feedback-analysis) - This use case demonstrates how the Slack API can be utilized to perform a company-wide survey by creating a dedicated channel to receive and track feedback replies.
26 changes: 17 additions & 9 deletions ballerina/Package.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,39 @@

To use the Slack Connector you need to be signed in to [Slack](https://slack.com/).

![Sign In Page](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-slack/master/docs/setup/resources/sign-in.png)
<img src=https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-slack/master/docs/setup/resources/sign-in.png alt="Sign-In Page" style="width: 70%;">

If you haven't created an account already, you can create it [here](https://slack.com/get-started#/createnew).

### Step 1: Create a new Slack application
### Step 1: Create a new Slack application

1. Navigate to your apps in [Slack API](https://api.slack.com/) and create a new Slack app.

![Create Slack App](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-slack/master/docs/setup/resources/create-slack-app.png)
<img src=https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-slack/master/docs/setup/resources/create-slack-app.png alt="Create Slack App" style="width: 70%;">

2. Provide an app name and choose a workspace of your choice.

![Create Slack App Popup](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-slack/master/docs/setup/resources/create-slack-app-2.png)
<img src=https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-slack/master/docs/setup/resources/create-slack-app-2.png alt="Create Slack App Popup" style="width: 70%;">

3. Click on the "Create App" button.

### Step 2: Add scopes to the token
### Step 2: Add scopes to the token

1. Once the application is created, go to the "Add Features and Functionality" section and click on "Permissions" to set the token scopes.

![Add Features and Functionality](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-slack/master/docs/setup/resources/add-features.png)
<img src=https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-slack/master/docs/setup/resources/add-features.png alt="Add features and functionality" style="width: 70%;">

2. In the **User Token Scopes** section set the following token scopes.

![User Token Scopes](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-slack/master/docs/setup/resources/token-permissions.png)
<img src=https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-slack/master/docs/setup/resources/token-permissions.png alt="User Token Scopes" style="width: 70%;">

3. Install the application to workspace.

![Install to workspace ](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-slack/master/docs/setup/resources/install-workspace.jpg)
<img src=https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-slack/master/docs/setup/resources/install-workspace.jpg alt="Install to workspace" style="width: 70%;">

4. Copy the OAuth token that is generated upon installation.

![Copy Token](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-slack/master/docs/setup/resources/copy-token.jpg)
<img src=https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-slack/master/docs/setup/resources/copy-token.jpg alt="Copy token" style="width: 70%;">


## Quickstart
Expand Down Expand Up @@ -82,3 +82,11 @@ json postMessageResponse = check slack->/chat\.postMessage.post({channel: "gener
```bash
bal run
```

## Examples

The `Slack` connector provides practical examples illustrating usage in various scenarios. Explore these [examples](https://github.com/ballerina-platform/module-ballerinax-slack/tree/master/examples), covering the following use cases:

1. [Automated Survey Report](https://github.com/ballerina-platform/module-ballerinax-slack/tree/master/examples/automated-survey-report) - This use case demonstrates how the Slack API can be utilized to generate a summarized report of daily stand up chats in the general channel.

2. [Survey Feedback Analysis](https://github.com/ballerina-platform/module-ballerinax-slack/tree/master/examples/survey-feedback-analysis) - This use case demonstrates how the Slack API can be utilized to perform a company-wide survey by creating a dedicated channel to receive and track feedback replies.
1 change: 1 addition & 0 deletions examples/automated-summary-report/.github/README.md
4 changes: 4 additions & 0 deletions examples/automated-summary-report/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
org = "wso2"
name = "automated_summary_report"
version = "0.1.0"
distribution = "2201.9.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Automated summary report

This use case demonstrates how the Slack API can be utilized to generate a summarized report of daily stand up chats in the general channel.

## Prerequisites

1. Generate a Slack token to authenticate the connector as described in the [Setup guide](https://central.ballerina.io/ballerinax/slack/latest#prerequisites).

2. For each example, create a `Config.toml` file with the related configuration. Here's an example of what your `Config.toml` file should look:

```toml
token = "<token>"
```

## Run the example

Execute the following command to run the example:

```ballerina
bal run
```
69 changes: 69 additions & 0 deletions examples/automated-summary-report/main.bal
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import ballerina/io;
import ballerina/log;
import ballerinax/slack;

configurable string token = ?;

# Holds slack channel information.
type ChannelType record {
string id;
};

# Holds response struture of the channels list.
type Channels record {|
boolean ok;
ChannelType[] channels;
|};

# Holds information of each text
type TextType record {
string text;
};

# Holds the response structure of the conversation history.
type History record {
boolean ok;
TextType[] texts;
};

// Initialize the Slack client with the provided token.
final slack:Client slack = check new Client({
auth: {
token: value
}
});

public function main() returns error? {
// Fetch the list of channels.
json channelResponse = check slack->/conversations\.list();
Channels channels = check channelResponse.cloneWithType();

// Array to store the latest text messages from each channel.
string[] latestText;

// Iterate through each channel to get the latest message.
foreach ChannelType channel in channels.channels {
// Fetch the conversation history for the current channel.
json historyResponse = check slack->/conversations\.history({channel: channel.id});
History history = check historyResponse.cloneWithType();

// Get the latest text message from the conversation history.
TextType[] texts = history.texts;
latestText.push(texts[0].text);
}

// Construct the stand-up report message.
string textMessage = string `Automated Stand Up Report: ${"\n"}${
<string>from [int, string] [index, text] in latestText.enumerate()
select string `${index + 1}. ${text}${"\n"}`
}`;

// Post the stand-up report message to the "general" channel.
json|error postMessageResult = slack->/chat\.postMessage.post({channel: "general", text: textMessage});

if postMessageResult is error {
log:printError("Failed to post message to Slack", postMessageResult);
} else {
log:printInfo("Message posted successfully");
}
}

0 comments on commit 0a06fac

Please sign in to comment.