Skip to content

Commit

Permalink
Make variables constant, move types to another file and remove redunt…
Browse files Browse the repository at this point in the history
…ant checks
  • Loading branch information
Chilliwiddit committed Jul 5, 2024
1 parent f257196 commit 6cfa09e
Showing 1 changed file with 6 additions and 30 deletions.
36 changes: 6 additions & 30 deletions examples/survey-feedback-analysis/main.bal
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,8 @@ import ballerinax/slack;

configurable string token = ?;

string channelName = "survey-coordination";
string surveyRequestMessage = "Reply to this survey message to give input on the company";

type MessagesItem record {
string text;
string thread_ts;
string ts;
string 'type;
string user;
string parent_user_id?;
string last_read?;
int reply_count?;
boolean subscribed?;
int unread_count?;
};

type Response_metadata record {
string next_cursor;
};

type RepliesResponse record {
boolean has_more;
MessagesItem[] messages;
boolean ok;
Response_metadata response_metadata;
};
final string channelName = "survey-coordination";
final string surveyRequestMessage = "Reply to this survey message to give input on the company";

final slack:Client slack = check new ({
auth: {
Expand All @@ -58,28 +34,28 @@ public function main() returns error? {
// Create a new channel for the survey
json|error createChannelResponse = check slack->/conversations\.create.post({name: channelName});
if createChannelResponse is error {
log:printError("Error creating the survey conversation: ", createChannelResponse);
log:printError(createChannelResponse.message());
return;
}

// Post a message to the conversation created and get the timestamp of the message
json|error sendMsgResponse = slack->/chat\.postMessage.post({channel: channelName, text: surveyRequestMessage});
if sendMsgResponse is error {
log:printError("Error posting the survey message: ", sendMsgResponse);
log:printError(sendMsgResponse.message());
return;
}
string messageTimestamp = check sendMsgResponse.message.ts;

// Check for replies to the survey message
json|error repliesResponse = slack->/conversations\.replies({channel: channelName, ts: messageTimestamp});
if repliesResponse is error {
log:printError("Error getting replies to the survey message: ", repliesResponse);
log:printError(repliesResponse.message());
return;
}

RepliesResponse|error replies = repliesResponse.cloneWithType();
if replies is error {
log:printError("Error mapping the JSON response to the RepliesResponse type: ", replies);
log:printError(replies.message());
return;
}

Expand Down

0 comments on commit 6cfa09e

Please sign in to comment.