How to send a message in the Slack channel using Flutter?

Gagandeep Gambhir

I am creating an attendance app in which if an employee got the approval on leave request, then the app should send a message in the Slack channel.

I have seen this flutter package on the pub but it is not very helpful:-

https://pub.dev/packages/flutter_slack_oauth

Any idea on how I can send a message in the Slack channel using Flutter?

Gagandeep Gambhir

Finally got the answer, and wants to share :)

Here is the slack API URL to create a new app:-

https://api.slack.com/apps

After creating a new app, activate the Incoming Webhooks feature:-

enter image description here

Grab the webhook URL for your workspace, and make a request via this Flutter function:-

import 'dart:convert';
import 'package:http/http.dart' as http;

sendSlackMessage(String messageText) {
  //Slack's Webhook URL
  var url = 'https://hooks.slack.com/services/TA******JS/B0**********SZ/Kk*******************1D';

  //Makes request headers
  Map<String, String> requestHeader = {
    'Content-type': 'application/json',
  };

  var request = {
    'text': messageText,
  };

  var result = http
      .post(url, body: json.encode(request), headers: requestHeader)
      .then((response) {
    print(response.body);
  });
  print(result);
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Hubot Slack: How to send message includes channel link?

hey guys, i'm using slack for alert message to send invoice data from my api To slack channel

Slack Incoming Web Hooks - Send message @channel

How to send message to my channel using telethon

Unable to send a message to specific channel in Slack with Hubot - SlackRTMError: no channel id

How to send user a message and create a channel right after installation of Slack app

How to send a message to a specific channel

How to send message to tagged channel?

Send message to Slack using webhook in flask

How can a Slack bot detect a direct message vs a message in a channel?

How to send message to Slack listening channels?

How to upload a file to a slack channel using a bot

Message sent to slack channel using python script is not properly aligned

Getting the shareable link to a channel message using Slack API

Adding button to Slack Channel Message using Zapier Integration

sending message to slack channel using PHP/Guzzle prints "Array"

Send message to channel at random using lists

How to use variable in gitlab-ci to send notification in a slack channel

How to send a error message in a specific channel

How to send a message to a Channel on all Servers

How to send ad-hoc app download link itms-service on slack using message buttons or link

How to broadcast message using channel

Trying to Load A Message Payload from a JSON File in Bash to Send to Slack Channel

Slack bot fails to send message to restricted general channel via chat.postMessage

Send message to channel in a function

How to properly tag a user using message.channel.send in discord.js

How can I send a message to a specific channel using Discord.py?

How do you make a bot send a message to an specific guild in a specific channel without using commands

How could I send the message to the specific channel using discord.py?