slackapi / deno-slack-api Goto Github PK
View Code? Open in Web Editor NEWSlack API Client for Deno Run on Slack projects
Home Page: https://api.slack.com/automation
License: MIT License
Slack API Client for Deno Run on Slack projects
Home Page: https://api.slack.com/automation
License: MIT License
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
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.
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
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
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.
x
in each of the [ ]
)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.
I can't sign CLA from Contributing guidelines. I found an error.
I want to contribute but I can't now.
x
in each of the [ ]
)**Access to https://cla-assistant.io/slackapi/deno-slack-api
A developer can begin to sign CLA.
deno-slack-api version:
Deno version:
OS version(s):
Add any other context about the problem here.
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'
}
Now, apiCall()
only supports POST method.
deno-slack-api/src/base-client.ts
Line 42 in 368e406
But Slack API has other HTTP methods.
So apiCall
needs to support other HTTP methods.
apiCallWithHTTPMethods()
async apiCallWithHTTPMethods(
http_methods: string,
method: string,
data: SlackAPIMethodArgs = {},
): Promise<BaseResponse> {
}
apiPostCall()
, apiGetCall()
, apiDeleteCall()
and morex
in each of the [ ]
)A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.