@graphai/slack_agent 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,42 @@
1
+
2
+ # @graphai/slack_agent for GraphAI
3
+
4
+ Slack message agents for GraphAI.
5
+
6
+ ### Install
7
+
8
+ ```sh
9
+ yarn add @graphai/slack_agent
10
+ ```
11
+
12
+ ## setup
13
+
14
+ ### Acquiring a Slack Token for Posting Messages
15
+
16
+ 1. **Obtain a Slack Token:**
17
+ - Go to the [Slack API Developer Portal](https://api.slack.com/apps) and select or create your app.
18
+ - Follow the steps in the **Permissions** or **Authentication** section to generate the necessary token for your use case (e.g., user token, bot token).
19
+
20
+ 2. **Set the Token as an Environment Variable:**
21
+ - Export the token as an environment variable by running the following command in your terminal:
22
+ ```bash
23
+ export SLACK_TOKEN=your-slack-token-here
24
+ ```
25
+
26
+ 3. **Using a Bot Token:**
27
+ - If you are using a bot token, ensure that the bot is added to the channel where you intend to post messages. This can be done from the Slack app by inviting the bot to the relevant channel.
28
+
29
+ ### Usage
30
+
31
+ ```typescript
32
+ import { GraphAI } from "graphai";
33
+ import { slackAgent } from "@graphai/slack_agent";
34
+
35
+ const agents = { slackAgent };
36
+
37
+ const graph = new GraphAI(graph_data, agents);
38
+ const result = await graph.run();
39
+ ```
40
+
41
+
42
+
@@ -5,6 +5,12 @@ const web_api_1 = require("@slack/web-api");
5
5
  const slackAgent = async ({ params, namedInputs }) => {
6
6
  const token = process.env.SLACK_TOKEN ?? namedInputs.slack_token;
7
7
  const channel = params.post_channel;
8
+ if (!token) {
9
+ throw new Error("SLACK_TOKEN is not set in environment variables.");
10
+ }
11
+ if (!channel) {
12
+ throw new Error("Slacl post_channel is not set in params.");
13
+ }
8
14
  const message = namedInputs.message ?? params.message;
9
15
  const text = Array.isArray(message) ? message.join("\n") : message;
10
16
  const web = new web_api_1.WebClient(token);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphai/slack_agent",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "Slack message agents for GraphAI.",
5
5
  "main": "lib/index.js",
6
6
  "files": [
@@ -10,7 +10,9 @@
10
10
  "build": "tsc",
11
11
  "eslint": "eslint src --fix",
12
12
  "format": "prettier --write '{src,tests}/**/*.ts'",
13
+ "doc": "npx agentdoc",
13
14
  "test_run": "node --test --require ts-node/register ./tests/run_*.ts",
15
+ "test_graph": "node --test --require ts-node/register ./tests/run_graph.ts",
14
16
  "test": "node --test --require ts-node/register ./tests/test_*.ts",
15
17
  "ci": "yarn run format && yarn run eslint && yarn run test && yarn run build"
16
18
  },