not able to post message to slack with slack api and javascript?

自作多情 提交于 2020-06-17 09:43:48

问题


I had created an chat tab and in that I had showed the users list using slack access token now when I click the user the respective user id and input tag and send button will be shown the html css and js code is like this THE CODE PEN LINK IS THIS: https://codepen.io/lakshmi123__/pen/yLYGoVP

Now I had wrote js code for posting a message to the user

 window.onload = function(){
      var form = document.getElementById('msg_send_btn');
      var input = document.getElementById("write_msg").value
      var channel = document.getElementById("insertName").value

      form.onclick = function(event) {
        event.preventDefault();
        var mData = new FormData();
        mData.append('token', 'xoxb-237781680599-1126148466947-kI0FF91IR6Z6vVCuZgaPyELO');
        mData.append('channel', channel);
        mData.append('text',input);
        mData.append('as_user', 'true');
        var xhr = new XMLHttpRequest();
        xhr.open('POST','https://slack.com/api/chat.postMessage', true);
        // Set up a handler for when the request finishes.
        xhr.onload = function () {
          if (xhr.status === 200) {
            console.log("posted");
          } else {alert('An error occurred!');
      }
    };
    xhr.send(mData);
  }
}

Here in the above code in the place of channel and input If I specify the channel id and text it is been posting to respective channel but here what I want is when I click on the user the user id and type a message will be shown in the right side pane so I took them using getelemenentbyid and used that variables in channel and text but the message is not posting

For example If I click satya user the id on the top of the type a message should get into channel variable and the text which I type after clicking should be get into the input variable.

can anyone help me out of this?

来源:https://stackoverflow.com/questions/61913925/not-able-to-post-message-to-slack-with-slack-api-and-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!