0
votes

Im trying to post message into Slack from external service with using "Incoming Webhooks", but it does not work.

For now , I got a error from developer console of Chrome which is 500 error. *The purpose of this coding is for chat app using slack.

Does anyone know how to post message into Slack?

        var module = angular.module('myapp',[]);
        module.controller("main", function($scope,$http){
        $scope.users = [{"text":"message"},];
        $scope.addUser = function(){
        //push data into list "$scope.users" for debug
        $scope.users.push({"text":$scope.txt});
        $scope.text = "";
        var successCallback = function(respose){
            $scope.result = response.data;
            $log.info(response);
        };

        var errorCallback = function(respose){
            $scope.error = 'error';
        };



        var message = {
                "text": $scope.txt,
                "username":"",
                "icon_url":"",
                "icon_emoji":"",
                "channel":"#XXX",

            };

        var configs = {
                headers : {
                    'Content-Type': 'application/json'
                }
            };

            $http({
                        method : "POST",
                        url : "https://hooks.slack.com/services/XXX/XXX/XXX",
                        payload : message,
                        config : configs
            }).then(successCallback,errorCallback);
    };
});
1
"For now, I got a error from developer console of Chrome which is 500 error." Please share the actual error you're seeing? - user94559

1 Answers

0
votes

I'm unfamiliar with Angular, but it looks from the documentation like your call to $http is wrong? You're passing a payload field when I think you mean data?

I'm also not sure the Content-Type header is needed... I believe JSON is the default. So I'd try just:

$http({ method: 'POST', url: '...', data: message }).then(...);

But you should be able to see the request and response in Chrome's developer tools, and hopefully that will make it clear whether you're sending what you expect to the server.