728x90
dependencies {
    // Other dependencies...
    implementation 'com.slack.api:slack-java-api:2.10.0'
}

요로코롬 2.10.0 을 납치해주면 될 것 같지만 작동하지 않는다.

 

Gradle

Do you prefer using Gradle? Let’s try installing the library with Gradle. The steps are quite similar to Maven, but there are some differences.

build.gradle

Place build.gradle in the root directory of your Java project. We don’t have any requirements for Gradle versions.

plugins {
  id("application")
}
repositories {
  mavenCentral()
}
dependencies {
  implementation("com.slack.api:slack-api-client:1.30.0")
}
application {
  mainClassName = "Example"
}

As with the Maven section, let’s create a class named Example with the main method. Then, run it from your IDE or hit gradle run on your terminal. You’ll see the same stdout.

In summary, the things you’ve done here are:

  • ✅ JDK 8 or higher installed (if not, run brew install openjdk@11 for macOS / visit OpenJDK website for others)
  • ✅ Gradle installed (if not, run brew install gradle for macOS / visit their website for others)
  •  build.gradle having slack-api-client as a dependency
  •  src/main/java/Example.java with the main method

Gradle for Kotlin

 

 

위에처럼 1.30.0 에 대한 부분을 build.gradle 에 의존성 결과로 적용해준 이후에 import 할 수 있었다.

특히 코드에서 몇가지 없는 부분들이 있는데, 버전이 올라감에 따라서 .get method 등이 deprecated 되었다.

https://slack.dev/java-slack-sdk/guides/web-api-client-setup

 

Installation | Slack SDK for Java

API Client Installation The first step to using the Slack API client is installing the slack-api-client module. This guide shows you how to set up using Maven, Gradle, and by building from source on your own. Prerequisites Installing OpenJDK 8 or higher LT

slack.dev

 

728x90

The Cannot resolve table 'user_group' is a warning that's typically seen in IntelliJ IDEA, it's not actually an error. It happens because IntelliJ IDEA does not know about the existence of a table named user_group because it's an intermediary table created by Hibernate to manage @ManyToMany relationships, not a table that you've explicitly created yourself.

The Hibernate runtime knows to create the user_group table based on the configuration in your User entity, but IntelliJ IDEA's static code analysis doesn't know this, and so it raises a warning.

You can safely ignore this warning. When you run your application, Hibernate will automatically create the user_group table for you.

However, if you want to get rid of this warning in IntelliJ IDEA, you can use the JPA Console to update the IntelliJ IDEA schema:

  1. Open the Persistence tool window by going to View -> Tool Windows -> Persistence.
  2. Click on the JPA Console tool button.
  3. In the JPA Console, execute this command: update

This will update the IntelliJ IDEA schema with your Hibernate/JPA schema and the warning should go away. Please ensure that you have correctly set up the data source in IntelliJ IDEA.

Remember, Cannot resolve table is a warning from the IDE and not an error from the Java compiler or the runtime environment. Your code should compile and run correctly despite this warning.

728x90

JPA 는 ORM 으로써 내부적으로 별도로 선언하지 않은 부분에 대해서 자동으로 만들어준다는 점에 의해서 굉장히 예쁘고 사랑스럽지만 종종 개같은 경우를 만들 때가 있다.

 

그 중 하나가 미리 예약된 예약어 같은 케이스인데, 그런 예약어를 보게 된다면 아래와같은 에러를 마주칠 수가 있다.

로그를 한땀한땀 해석해보자면, GenerationTarget (생성하려는 대상)이 명령어를 수용하는 도중에 예외에 맞닥들였다는 것이다. 특히 이 부분에서 DDL "alter table if exists group_users add constraint xxxx" 라고 나오는데 문제가 되는 부분이 바로

"group_users" 가 되시겠다.

 

group 은 사실 스프링 예약어라기 보다는 SQL 에서 예약된 예약어로써 다들 알다시피 group by 에서 납치해다 쓰는 경우가 많은데, 이 때문에 생성하면서 alter table 로 외래키 제약조건을 생성하려다가 망할놈의 에러를 만난 것이다

 


그래서 어떻게 해결하는데?

약 2가지 정도의 해결 방법이 떠오르는데, 첫번째 방법은 그냥 감싸주는 것이다.

 

@Entity
@Table(name = "article")
public class Article {
	@Id
	private Long id;
	private String title;
	private String description;
	
	@Column(name = "\"group\"")
	private String group;
}

예를 들어 내부에 정의된 속성 중 group 이라는 놈이 걸릴꺼니까 저렇게 감싸버리고, 그리고 다른 경우에 Entity 하위에 나와같이 Table 명 자체를 group으로 주고 싶은 경우에는 @Table(name = "\"group\"") 과 같이 주면 되겟다.

 

그런데 이 짓거리를 언제 다 하냐 이말이지.

그래서 나온 것이 application.properties 쪽이나 yml 에서 떄려잡는 것이다.

 

spring:
  jpa:
    properties:
      hibernate:
        globally_quoted_identifiers: true # 이 설정을 추가해준다.
        show_sql: true # 쿼리를 출력해준다.
        format_sql: true # 쿼리를 예쁘게 출력해준다.
        generate_statistics: true # 쿼리 수행 통계를 확인할 수 있다.

 

properties 쪽에서 때려잡은 나는 아랫쪽의 것을 사용해줫다

# 이 설정을 추가해준다.
spring.jpa.properties.hibernate.globally_quoted_identifiers=true

# 참고로 아래 설정은 실행된 SQL 쿼리를 출력해준다.
spring.jpa.properties.hibernate.show_sql=true
spring.jpa.properties.hibernate.format_sql=true

# 쿼리 수행 통계를 확인할 수 있다.
spring.jpa.properties.hibernate.generate_statistics=true


결론 = 데이터베이스 예약어나 키워드를 Entity 가 정의된 클래스에서 사용하지 말자

728x90

서두

일단 시작하기전에 Slack API 를 연동할 방법을 곰곰히 생각해보았다. 킹치만 우리에게는 구글신이라는 것이 있기에 굳이 삽질을 할 필요가 없다.

 

1. Slack Api 에 들어간 다음 Sign in 을 한다 

 - 여기서 당연히 Account 가 없으면 가입을 해야되는 부분이고, 나는 일단 프로젝트를 위해서 그냥 만들어줬다.

 

2. Create App 을 한다

타입이 2가지가 있는데, (제 배에는 구멍이 2개죠..)  Slack 에서 만들어놓은 Basic UI 방식이 있고, 그 이외에 매니페스트 방식이 있다. 기본적으로 구글신에서 안내하는것은 Basic UI 를 따르니까 보고 쓱싹 생성하자.

manifest  쓰면 앱에 관한 설정의 대부분을 관리할 수 있따는 겁니다. 근데 YAML 이랑 JSON 을 때려잡아야 하죠

 

 

다 만들어서 아랫쪽으로 내려보면 이렇게 설명이 있다.

Part2

여기서 Slack 을 일종의 Bot 용도로 써서 알리미 용도로 쓸거니까 추가 Method 기능에서 Bot을 얌채같이 클릭해준다.

 

 

 

여기서 Install App 을 해서 상호작용을 하려면, 기본적으로 Permission 이 있어야 한다. (리눅스 기반에서는 다 그렇잖아? 서버도 그렇구)

 

 

이렇게 OAuth & Permission 탭에서 하단부로 들어가면 Bot 에 대한 Permission Scope 를 정할 수 있는 곳이 보인다.

이게 100% 맞는지는 모르겠지만, 니가 Bot 을 무슨 용도로 쓰고, Bot에 어떤 권한을 줄꺼니로 느낌이 든다

"Add an OAuth Scope" 를 클릭하면 콤보박스가 하나 뜨는데, 거기서 필요한 Permission 을 골라주면 되겠다.

내 경우는 채널에 대한 메세지를 알람처럼 보낼 것이기 때문에 chat:write 을 부여했다.

 

그러면 위와 같이 Bot 이랑 Permission 에 설정했다고 체크박스와 함께 화려한 불빛이 나를 감싼다.

하단부의 Install your app 에서 workspace 에 설치를 진행했다.

 

이제 Slack API 에서 내가 만든 App 에 메세지를 보낼 수 있다. (물론 메세지 이외에 다른 짓도 하고싶다면, API 의 사용 용도에 따라서 삽질을 진행하면 되겟다.)

 

 

Part3

Incomming Webhooks 활성화 하기

 

일반적으로 Bot 토큰이나 등등에 대해서 안뜬다면 그냥 Incomming Webhook 에 들어와서 저기 위에 있는 Off를 On으로 바꿔주면 나같이 위에서 삽질을 했다면 퍼미션 변경한다고 뜬다. 진행해보자

 

 

그리고 번외의 채널 리스트 불러오기도 구현해보자

이 부분에는 Scope 에서 channels:read 퍼미션이 필요하다.

+ Recent posts