fix: use default channel and update tests

old-agentic-v1^2
Philipp Burckhardt 2023-06-10 14:44:18 -04:00 zatwierdzone przez Travis Fischer
rodzic df03a81ddf
commit ba7e9709f7
2 zmienionych plików z 15 dodań i 11 usunięć

Wyświetl plik

@ -56,16 +56,16 @@ export type SlackBlock = {
}
export type SlackPostMessageParams = {
/**
* The ID of the channel to send the message to.
*/
channel: string
/**
* The text of the message to send.
*/
text: string
/**
* The ID of the channel to send the message to.
*/
channel?: string
/**
* The timestamp of a parent message to send the message as a reply to.
*/
@ -165,8 +165,14 @@ export class SlackClient {
* Sends a message to a channel.
*/
public async sendMessage(options: SlackPostMessageParams) {
if (!options.channel && !this.defaultChannel) {
throw new Error('Error: No channel specified')
}
const res = await this.api.post('chat.postMessage', {
json: options
json: {
channel: this.defaultChannel,
...options
}
})
return res.json<SlackMessage>()
}

8
test/slack.test.ts vendored
Wyświetl plik

@ -5,7 +5,7 @@ import { SlackClient } from '@/services/slack'
import './_utils'
test('SlackClient.sendMessage', async (t) => {
if (!process.env.SLACK_API_KEY) {
if (!process.env.SLACK_API_KEY || !process.env.SLACK_DEFAULT_CHANNEL) {
return t.pass()
}
@ -13,14 +13,13 @@ test('SlackClient.sendMessage', async (t) => {
const client = new SlackClient()
const result = await client.sendMessage({
text: 'Hello World!',
channelId: 'D05B1AHA55L'
text: 'Hello World!'
})
t.truthy(result)
})
test('SlackClient.sendAndWaitForReply', async (t) => {
if (!process.env.SLACK_API_KEY) {
if (!process.env.SLACK_API_KEY || !process.env.SLACK_DEFAULT_CHANNEL) {
return t.pass()
}
@ -31,7 +30,6 @@ test('SlackClient.sendAndWaitForReply', async (t) => {
async () => {
await client.sendAndWaitForReply({
text: 'Please reply to this message with "yes" or "no"',
channelId: 'D05B1AHA55L',
validate: () => false, // never validate so we timeout
timeoutMs: 1000,
intervalMs: 100