fix: Integration and auth problems wrt slack and twitter
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
|
||||
|
||||
type FindMessageOptions = {
|
||||
query: string;
|
||||
@@ -8,6 +8,11 @@ type FindMessageOptions = {
|
||||
};
|
||||
|
||||
const findMessage = async ($: IGlobalVariable, options: FindMessageOptions) => {
|
||||
const message: {
|
||||
data?: IJSONObject;
|
||||
error?: IJSONObject;
|
||||
} = {};
|
||||
|
||||
const headers = {
|
||||
Authorization: `Bearer ${$.auth.data.accessToken}`,
|
||||
};
|
||||
@@ -24,20 +29,20 @@ const findMessage = async ($: IGlobalVariable, options: FindMessageOptions) => {
|
||||
params,
|
||||
});
|
||||
|
||||
if (response.integrationError) {
|
||||
message.error = response.integrationError;
|
||||
return message;
|
||||
}
|
||||
|
||||
const data = response.data;
|
||||
|
||||
if (!data.ok) {
|
||||
if (data.error === 'missing_scope') {
|
||||
throw new Error(
|
||||
`Error occured while finding messages; ${data.error}: ${data.needed}`
|
||||
);
|
||||
}
|
||||
|
||||
throw new Error(`Error occured while finding messages; ${data.error}`);
|
||||
message.error = data;
|
||||
return message;
|
||||
}
|
||||
|
||||
const messages = data.messages.matches;
|
||||
const message = messages?.[0];
|
||||
message.data = messages?.[0];
|
||||
|
||||
return message;
|
||||
};
|
||||
|
@@ -19,11 +19,16 @@ export default {
|
||||
},
|
||||
});
|
||||
|
||||
if (response.integrationError || response.data.ok === 'false') {
|
||||
if (response.integrationError) {
|
||||
channels.error = response.integrationError;
|
||||
return channels;
|
||||
}
|
||||
|
||||
if (response.data.ok === 'false') {
|
||||
channels.error = response.data.error;
|
||||
return channels;
|
||||
}
|
||||
|
||||
channels.data = response.data.channels.map((channel: IJSONObject) => {
|
||||
return {
|
||||
value: channel.id,
|
||||
|
Reference in New Issue
Block a user