Vue+electron 도구로 Slack에게 메시지 보내기
Vue + electron 도구로 Slack에게 메시지 보내기
 일의 발단
새롭게 아르바이트로 입사한 기업의 배속팀의 근태규칙
출사, 휴식 개시, 휴식 종료, 퇴사 시 특정 채널에 각각에 대응하는 이모티콘을 송신한다.
비교적 귀찮은 ... 덧붙여서 이것 이외에도 근태 시스템과 타임 카드의 3 중문.
 했던 일
제목대로 Slack의 API를 Vue + electron의 도구로 두드려 원 클릭으로 출사 퇴사 등의 이모티콘을 보낼 수 있었습니다.
 코드
vue init 에서 electron-vue 최소한의 템플릿에서 만들고 있습니다.
App.vue<template>
  <div id="app">
    <div class="cont">
      <div class="button" style="border-color: rgb(129,188,189); color: rgb(129,188,189);" @click="send(1)">
        <h2>出社</h2>
      </div>
      <div class="button" style="border-color: rgb(235,115,62); color: rgb(235,115,62);" @click="send(2)">
        <h2>休憩</h2>
      </div>
      <div class="button" style="border-color: rgb(235,115,62); color: rgb(235,115,62); " @click="send(3)">
        <h2>再開</h2>
      </div>
      <div class="button" style="border-color: rgb(58,61,145); color: rgb(58,61,145);" @click="send(4)">
        <h2>退社</h2>
      </div>
    </div>
  </div>
</template>
<script>
import { SlackOAuthClient } from 'messaging-api-slack';
export default {
  name: "kintary",
  methods: {
    send(type) {
      let mes = ''
      switch(type) {
        case 1:
          mes = ':sagyo-kaishi-作業開始_green:'
          break;
        case 2:
          mes = ':sagyo-ohiru-kyukei-お昼休憩_orange:'
          break;
        case 3:
          mes = ':sagyo-saikai-作業再開_orange:'
          break;
        case 4:
          mes = ':sagyo-shuryo-作業終了_navy:'
          break;
      }
      const client = SlackOAuthClient.connect(
        'xoxp-slackから取得したアクセストークン(管理者じゃなくても自分のものは取得できた)'
      );
      client.postMessage('frontteam_kintai', mes, { as_user: true });
    }
  }
};
</script>
<style>
#app {
  height: 100vh;
  width: 100vw;
  display: flex;
  justify-content: center;
  align-items: center;
}
.cont {
  width: 480px;
  height: 120px;
  display: flex;
  justify-content: center;
  align-items: center;
}
.button {
  height: 100px;
  width: 100px;
  border-radius: 50px;
  border: 3px solid;
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 10px;
}
.button:hover {
  opacity: 0.6;
}
.button:active {
  transform: scale(0.95);
}
</style>
 고민한 곳
Slack의 API를 두드릴 때, Axios.post에서 두드렸더니 CORS 관련 오류가 나왔다.
↓
매우 편리한 npm 모듈이 있었기 때문에 온순하게 그것을 이용, import해 설정해 .postMessage만으로 이용할 수 있었다.
※as_user 옵션을 true로 하는 것으로, token을 취득한 User로서 투고를 할 수 있다.
 할 수있는 것
 
 미래
제대로 빌드하고 싶다.
                
                    
        
    
    
    
    
    
                
                
                
                
                    
                        
                            
                            
                            Reference
                            
                            이 문제에 관하여(Vue+electron 도구로 Slack에게 메시지 보내기), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
                                
                                https://qiita.com/unotovive/items/0e0a117340eaa04c9f77
                            
                            
                            
                                텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                            
                            
                                
                                
                                 우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                            
                            
                        
                    
                
                
                
            
<template>
  <div id="app">
    <div class="cont">
      <div class="button" style="border-color: rgb(129,188,189); color: rgb(129,188,189);" @click="send(1)">
        <h2>出社</h2>
      </div>
      <div class="button" style="border-color: rgb(235,115,62); color: rgb(235,115,62);" @click="send(2)">
        <h2>休憩</h2>
      </div>
      <div class="button" style="border-color: rgb(235,115,62); color: rgb(235,115,62); " @click="send(3)">
        <h2>再開</h2>
      </div>
      <div class="button" style="border-color: rgb(58,61,145); color: rgb(58,61,145);" @click="send(4)">
        <h2>退社</h2>
      </div>
    </div>
  </div>
</template>
<script>
import { SlackOAuthClient } from 'messaging-api-slack';
export default {
  name: "kintary",
  methods: {
    send(type) {
      let mes = ''
      switch(type) {
        case 1:
          mes = ':sagyo-kaishi-作業開始_green:'
          break;
        case 2:
          mes = ':sagyo-ohiru-kyukei-お昼休憩_orange:'
          break;
        case 3:
          mes = ':sagyo-saikai-作業再開_orange:'
          break;
        case 4:
          mes = ':sagyo-shuryo-作業終了_navy:'
          break;
      }
      const client = SlackOAuthClient.connect(
        'xoxp-slackから取得したアクセストークン(管理者じゃなくても自分のものは取得できた)'
      );
      client.postMessage('frontteam_kintai', mes, { as_user: true });
    }
  }
};
</script>
<style>
#app {
  height: 100vh;
  width: 100vw;
  display: flex;
  justify-content: center;
  align-items: center;
}
.cont {
  width: 480px;
  height: 120px;
  display: flex;
  justify-content: center;
  align-items: center;
}
.button {
  height: 100px;
  width: 100px;
  border-radius: 50px;
  border: 3px solid;
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 10px;
}
.button:hover {
  opacity: 0.6;
}
.button:active {
  transform: scale(0.95);
}
</style>

미래
제대로 빌드하고 싶다.
Reference
이 문제에 관하여(Vue+electron 도구로 Slack에게 메시지 보내기), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/unotovive/items/0e0a117340eaa04c9f77텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)