k10a
k10a

Reputation: 1087

Can't post a channel in Slack: An API error occurred: not_in_channel

Want to send Slack notification to a channel the user registers in Firebase Cloud Function. Actually, I want to send a notification when the field contents change in Firestore, but it occurs API Error.

Error: An API error occurred: not_in_channel

It might be not Cloud Function error, should be Slack API error.

Oauth Scope:

enter image description here The Code:

firestore
  .collection("users")
  .doc(id)
  .get()
  .then(snapshot => {
    try {
        const token = snapshot.data().token;
        if (token) {
          const result = new WebClient(token).chat.postMessage({
            channel: snapshot.data().channel,
            text: "Posted!"
          });
          console.log(`Successfully send message ${result.ts}`);
        }
    } catch (error) {
      console.log(`Not authenticated to slack ${error}`);
    }
  });
});

Upvotes: 1

Views: 1543

Answers (1)

k10a
k10a

Reputation: 1087

You have to add App in the channel.

Upvotes: 4

Related Questions