sendLinkAndQr method
Implementation
Future<void> sendLinkAndQr({
required String slackBotToken,
required int fileSizeInBytes,
required File file,
required String channelId,
required String message,
required String downloadLink,
bool? isShareQR,
bool? isShareDownloadLink,
List<String>? mentions,
}) async {
if (isShareQR == true) {
await _uploadQrCode(
slackBotToken: slackBotToken,
fileSizeInBytes: fileSizeInBytes,
file: file,
channelId: channelId,
message: message,
downloadLink: downloadLink,
);
}
try {
// Step 4: Send the message with link and mentions
final formattedMentions = mentions?.map((id) => '<@$id>').join(' ') ?? '';
final finalMessage = '$message\n$formattedMentions';
final messageResponse = await dio.post(
'https://slack.com/api/chat.postMessage',
options: Options(
headers: {
'Authorization': 'Bearer $slackBotToken',
'Content-Type': 'application/json',
},
),
data: jsonEncode(
{
'channel': channelId,
'text':
'$finalMessage ${isShareDownloadLink == true ? "<$downloadLink|Download>" : ""}',
'blocks': [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text":
"🚀 *$finalMessage ${isShareDownloadLink == true ? "<$downloadLink|Download>" : ""}*"
}
},
if (isShareDownloadLink == true)
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {"type": "plain_text", "text": "Download Now"},
"style": "primary",
"url": downloadLink.toString()
}
]
}
]
},
),
);
if (messageResponse.data['ok']) {
Helpers.highlight('Message sent successfully to Slack.');
} else {
Helpers.showHighlight(
firstMessage: 'Error sending message:',
highLightmessage: messageResponse.data['error'].toString(),
);
}
} catch (e) {
Helpers.showHighlight(
firstMessage: 'Error while uploading QR to slack:',
highLightmessage: e.toString(),
);
exit(0);
}
}