Code Monkey home page Code Monkey logo

deno-slack-api's Introduction

deno-slack-api

codecov

Slack API Client for Deno Run on Slack projects

import { SlackAPI } from "https://deno.land/x/[email protected]/mod.ts";

const client = SlackAPI(token);

// ...or create a client with options
const client = SlackAPI(token, {
  slackApiUrl: "...",
});

await client.chat.postMessage({
  text: "hello there",
  channel: "...",
});

// respond to a response_url
await client.response("...", payload);

// use apiCall() w/ method name
await client.apiCall("chat.postMessage", {
  text: "hello there",
  channel: "...",
});

Requirements

A recent version of deno.

Versioning

Releases for this repository follow the SemVer versioning scheme. The SDK's contract is determined by the top-level exports from src/mod.ts and src/types.ts. Exports not included in these files are deemed internal and any modifications will not be treated as breaking changes. As such, internal exports should be treated as unstable and used at your own risk.

Running Tests

If you make changes to this repo, or just want to make sure things are working as desired, you can run:

deno task test

To get a full test coverage report, run:

deno task test:coverage

Getting Help

We welcome contributions from everyone! Please check out our Contributor's Guide for how to contribute in a helpful and collaborative way.

deno-slack-api's People

Contributors

aishwarya-chauhan avatar anabulsi avatar btoo avatar chris-skud avatar cyungslack avatar dependabot[bot] avatar filmaj avatar jmplexi avatar lucasmichot avatar mcodik avatar rrreeeyyy avatar ryu-727 avatar sbarksdale97 avatar selfcontained avatar seratch avatar shapirone avatar srajiang avatar stevengill avatar uhunnyslack avatar williambergamin avatar wongjas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

deno-slack-api's Issues

[BUG] Can't access CLA assistant

Describe the bug

I can't sign CLA from Contributing guidelines. I found an error.

I want to contribute but I can't now.

Requirements (place an x in each of the [ ])**

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

To Reproduce

Access to https://cla-assistant.io/slackapi/deno-slack-api

Expected behavior

A developer can begin to sign CLA.

Screenshots

sc

Reproducible in:

deno-slack-api version:

Deno version:

OS version(s):

Additional context

Add any other context about the problem here.

[FEATURE] Add `files.uploadV2` like the other Slack SDKs have

See https://slack.dev/node-slack-sdk/web-api#upload-a-file for docs on how this method works from a user perspective.

Here is the code from the node-slack-sdk for this method: https://github.com/slackapi/node-slack-sdk/blob/main/packages/web-api/src/file-upload.ts

@seratch has example code for deno-slack-sdk-based apps that use the above approach, more or less, that we could probably lift from: https://github.com/seratch/slack-timesheet/blob/412d9899c839fe24531a097ab0f1f68eb0513d2a/functions/internals/reports.ts#L549-L590

[FEATURE] expose block types

I'd like to have the block types exposed just like the NPM module:

For example with the nodejs module:

import type {
  ContextBlock,
  DividerBlock,
  HeaderBlock,
  SectionBlock,
} from 'npm:@slack/[email protected]'

I don't think the types are exposed in the deno module

Description of the problem being solved

Types for creating a chat request exposed.

[FEATURE] Add proper types to clients

Description of the problem being solved

Please add types to the client. Seems like all but a very few of the SlackAPIClient methods are untyped. This makes the DX very poor.

Alternative solutions

Generate your own types based on the docs, but this can be inaccurate

Requirements

Have accurate types for all endpoints of the APIClient

[FEATURE] apiCall support other HTTP methods

Description

Now, apiCall() only supports POST method.

method: "POST",

But Slack API has other HTTP methods.
So apiCall needs to support other HTTP methods.

Suggestion

  1. Add apiCallWithHTTPMethods()
  async apiCallWithHTTPMethods(
    http_methods: string,
    method: string,
    data: SlackAPIMethodArgs = {},
  ): Promise<BaseResponse> {
  }
  1. Add apiPostCall(), apiGetCall(), apiDeleteCall() and more

Requirements (place an x in each of the [ ])

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

[FEATURE] Retry requests if "tls handshake eof" error detected

I have a workflow that runs daily, haven't made changes to it for some time. Got this error today. Maybe a hiccup on the backend?

2023-11-13 08:00:50 [info] [Fn060X3USBNZ] (Trace=Tr0657KMM4GN) Function output:
        Caught error from user supplied module: TypeError: error sending request for url (https://slack.com/api/functions.completeSuccess): error trying to connect: tls handshake eof
            at async mainFetch (ext:deno_fetch/26_fetch.js:277:12)
            at async fetch (ext:deno_fetch/26_fetch.js:504:7)
            at async BaseSlackAPIClient.apiCall (file:///opt/runtime.js:44:22)
            at async Object.RunFunction [as function_executed] (file:///opt/runtime.js:1709:29)
            at async DispatchPayload (file:///opt/runtime.js:1790:16)
            at async run (file:///opt/runtime.js:1857:18)
            at async serveHttp (file:///opt/runtime.js:1885:38)
        Error responding HTTP 500 to webapp request: Http: connection closed before message completed

[QUERY] How to use files.upload to upload a binary file

Question

How does one use files.upload? I tried

import { Readable } from "node:stream";

// ...

      // This is a `ReadableStream<Uint8Array>`...
      const audio = (await fetch("https://upload.wikimedia.org/wikipedia/commons/7/71/George_Gershwin_2.ogg")).body!;

      const response = await client.files.upload({
        channels: "<channel ID>",
        title: "Title",
        initial_comment: "Comment",
        // ...which I adapt into a Node.js `Readable` here
        file: Readable.from(audio),
        filename: "audio.ogg",
        filetype: "ogg",
      });

With this code, the API response is {"ok":false,"error":"no_file_data"}. I was expecting this to work since the files.upload JavaScript sample code, whose docs do similar, refer to something like the above as the legacy way to upload files. My use case is simple so I think I'm ok with a legacy way, as long as it works. Thanks!

Context

Environment

"deno-slack-sdk/": "https://deno.land/x/[email protected]/",
"deno-slack-api/": "https://deno.land/x/[email protected]/",

deno 1.40.5 (release, aarch64-apple-darwin)
v8 12.1.285.27
typescript 5.3.3

ProductName: macOS
ProductVersion: 14.2.1
BuildVersion: 23C71
Darwin Kernel Version 23.2.0: Wed Nov 15 21:53:18 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T6000

Requirements

Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you are agreeing to those rules.

Return Response instead of BaseResponse

Description

Currently the base BaseSlackClient defines the return type of apiCall and response as Promise<BaseResponse> which represents the json payload returned by the Slack API.

This is an issue since users may want to access more then just the json payload from the Response such as headers and status codes.

In the next major release apiCall and response should return some version of Promise<[Response](https://deno.com/deploy/docs/runtime-response)> instead. It will be a breaking change.

Requirements (place an x in each of the [ ])

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

[BUG] Returning SlackAPIClient from an async function crashes Deno

The deno-slack versions

I don't have an import map, but deno_slack_api is 2.7.0 - also tested at 2.1.1

Deno runtime version

deno 1.44.4+86010be

OS info

ProductName:		macOS
ProductVersion:		14.4.1
BuildVersion:		23E224
Darwin Kernel Version 23.4.0: Fri Mar 15 00:10:42 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6000

(also tried on Alpine-1.43.2)

Describe the bug

Attempting to return SlackAPIClient from an async function causes Deno to fail with a top-level await promise never resolved. I've also ran this within a worker (my original production code) and in that scenario execution seems to simply... stop. No errors thrown.

Steps to reproduce

// mod.ts

import { SlackAPI } from "https://deno.land/x/[email protected]/mod.ts";

const getClientAsync = async () => {
  // This return style always fails
  return SlackAPI("foo");
};

const getClientNestedAsync = async () => {
  // Nesting it in an object succeeds
  return { c: SlackAPI("foo") };
};

const getClient = () => {
  // Returning from a non-async function succeeds
  return SlackAPI("foo");
};

const run = async () => {
  console.log("Running");
  SlackAPI("foo");
  console.log("Got inline client");

  getClient();
  console.log("Got client from func");

  await getClientNestedAsync();
  console.log("Got client from nested async func");

  await getClientAsync();
  console.log("Got client from async func");
};

if (import.meta.main) {
  await run();
}

Run with: deno run --allow-all mod.ts

Expected result

Should see all logs, including Got client from async func. More generally, I should be able to return the SlackClientAPI object without error from an async function.

Actual result

Running the above outputs:

Running
Got inline client
Got client from func
Got client from nested async func
error: Top-level await promise never resolved
  await run();
  ^
    at <anonymous> (file:///mod.ts:34:3)

If I move the call to getClientAsync anywhere else, it still immediately fails at the point it makes that call.

Note:

I've also raised an issue on Deno here: denoland/deno_core#828

It seems to me that Deno shouldn't behave this way, but also it might be something this project can workaround (since the SlackAPIClient is the first value I've seen exhibit this behaviour).

Potential typing issue with datastore API

Need to reproduce as a first step!

But, as reported in a feedback session by a community developer, with the following datastore:

export const OldestCodeReviewDatastore = DefineDatastore({
  name: 'code_review_datastore',
  attributes: {
    id: {
      type: Schema.types.string
    },
    timestamp: {
      type: Schema.types.string
    }
  },
  primary_key: 'id'
})

This code apparently returns an any type.

async function getOldestReview(client: SlackAPIClient, channel: string) {
  const oldestReview = await client.apps.datastore.get<typeof OldestCodeReviewDatastore.definition>({
    datastore: 'code_review_datastore',
    id: 'oldest_review_' + channel
  })

  if (!oldestReview.ok) {
    console.log('Error during request apps.datastore.get!', oldestReview)
    return '0'
  }

  return oldestReview?.item?.timestamp ?? '0'
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.