コード例 #1
0
def on_button_click():
    # 버튼 클릭은 SlackEventsApi에서 처리해주지 않으므로 직접 처리합니다
    payload = request.values["payload"]
    click_event = MessageInteractiveEvent(json.loads(payload))
    ordertxt = str(click_event.value)

    if 'chart_current' in ordertxt:
        message_list, attachments_list = _crawl_music_chart()

        for i in range(len(message_list)):
            slack_web_client.chat_postMessage(channel=click_event.channel.id,
                                              text=message_list[i],
                                              attachments=attachments_list[i])
            time.sleep(1)
#-------------작업중
#when yser clicked 장르별차트
    elif 'chart_genre' in ordertxt:

        slack_web_client.chat_postMessage(
            channel=click_event.channel.id,
            text=
            "`@<봇이름> [(발라드/댄스/팝)은 1,(랩/힙합)은 2,(알앤비/소울)은 3,(일렉트로닉)은 4,(락/메탈)은 5]` 과 같이 멘션해주세요."
        )

    #when user clicked 오늘의 노래
    elif 'chart_album' in ordertxt:
        message_list, attachments_list = today_musics()
        for i in range(len(message_list)):
            slack_web_client.chat_postMessage(channel=click_event.channel.id,
                                              text=message_list[i],
                                              attachments=attachments_list[i])
            time.sleep(1)

    return "OK", 200
コード例 #2
0
def on_button_click():
    # 버튼 클릭은 SlackEventsApi에서 처리해주지 않으므로 직접 처리합니다
    payload = request.values["payload"]
    click_event = MessageInteractiveEvent(json.loads(payload))
    Thread(target=click_Threding, args=(click_event, )).start()

    # Slack에게 클릭 이벤트를 확인했다고 알려줍니다
    return "OK", 200
コード例 #3
0
def handle_block_actions(data: dict):
    data["message"] = {"ts": data["container"]["message_ts"]}
    ah = MessageInteractiveEvent(data)
    result = block_interactor.interact(ah.action_id, action=ah)
    wr = None
    if result is not None:
        wr = webhook_response(ah.response_url, result)
    current_app.logger.info(
        f"Block action interaction for {ah.action_id} returning {result} - {wr}"
    )
    return "", 204
コード例 #4
0
def on_button_click():
    # 버튼 클릭은 SlackEventsApi에서 처리해주지 않으므로 직접 처리합니다
    payload = request.values["payload"]
    click_event = MessageInteractiveEvent(json.loads(payload))

    keyword = click_event.block_id
    dDay = int(click_event.value)

    yesterday = datetime.today().day - 1
    yttt = []
    for i in range(4):
        tmpYttt = yesterday + i
        if int(tmpYttt) < 10:
            yttt.append("0" + str(tmpYttt))
        else:
            yttt.append(str(tmpYttt))

    dateData = ""
    if dDay == 0:
        dateData = yttt[0]
    elif dDay == 1:
        dateData = yttt[1]
    if dDay == 2:
        dateData = yttt[2]
    elif dDay == 3:
        dateData = yttt[3]

    objectList = []
    objectList = crawlig(dateData)

    # 블록 처리 ##
    my_blocks = []
    for i in range(len(objectList)):
        m = objectList[i]
        titleBlockTmp = SectionBlock(text="*`\\\\\\\\\\\\\\\\\\\\\\\\\t\t" +
                                     "Day " + dateData + ". " + m.title +
                                     "\t\t///////////`*")
        imgBlockTmp = ImageBlock(
            image_url=m.img,
            alt_text="이미지가 안보이면 어쩔수 없지...",
        )
        contentBlockTmp = SectionBlock(fields=m.foods)

        my_blocks.append(titleBlockTmp)
        my_blocks.append(imgBlockTmp)
        my_blocks.append(contentBlockTmp)

    ## Post message to Chatbot ##
    slackWebClient_toChatbotPostMsg(click_event.channel.id,
                                    extract_json(my_blocks))

    # Slack에게 클릭 이벤트를 확인했다고 알려줍니다
    return "OK", 200
コード例 #5
0
def on_button_click():
    # 버튼 클릭은 SlackEventsApi에서 처리해주지 않으므로 직접 처리합니다
    payload = request.values["payload"]
    click_event = MessageInteractiveEvent(json.loads(payload))
    channel = click_event.channel.id

    KEY = click_event.action_id

    if KEY == EXPECT:
        sendMessage(channel, bus_expect(timeTable))
    else:
        sendMessage(channel, BusSection(KEY))

    return "OK", 200
コード例 #6
0
def on_button_click():
    # 버튼 클릭은 SlackEventsApi에서 처리해주지 않으므로 직접 처리합니다

    payload = request.values["payload"]
    click_event = MessageInteractiveEvent(json.loads(payload))

    global current
    # keyword = click_event.block_id
    current = int(click_event.value)

    # 다른 리스트로 블록을 재가공

    message_blocks = make_block.make_block(job_objects, current)
    slack_web_client.chat_postMessage(channel=click_event.channel.id,
                                      blocks=extract_json(message_blocks))
    # Slack에게 클릭 이벤트를 확인했다고 알려줍니다
    return "OK", 200
コード例 #7
0
ファイル: test.py プロジェクト: kimjw9302/RankingnewsChatbot
def on_button_click():
    # 버튼 클릭은 SlackEventsApi에서 처리해주지 않으므로 직접 처리합니다
    payload = request.values["payload"]
    click_event = MessageInteractiveEvent(json.loads(payload))
    print(payload)
    keyword = click_event.block_id
    new_price = int(click_event.value)

    # 다른 가격대로 다시 크롤링합니다.
    message_blocks = make_sale_message_blocks(keyword, new_price)

    # 메시지를 채널에 올립니다
    slack_web_client.chat_postMessage(channel=click_event.channel.id,
                                      blocks=extract_json(message_blocks))

    # Slack에게 클릭 이벤트를 확인했다고 알려줍니다
    return "OK", 200
コード例 #8
0
def on_button_click():
    # 버튼 클릭은 SlackEventsApi에서 처리해주지 않으므로 직접 처리합니다
    payload = request.values["payload"]
    click_event = MessageInteractiveEvent(json.loads(payload))

    func_Name = click_event.action_id
    user_input = click_event.value

    print('block id type:', type(func_Name))
    # 다른 가격대로 다시 크롤링합니다.
    if func_Name == '0':
        message_blocks = make_sale_message_blocks(user_input)
        slack_web_client.chat_postMessage(channel=click_event.channel.id,
                                          blocks=extract_json(message_blocks))
    elif func_Name == '1':
        message_blocks = make_hotel_message_blocks(user_input)
        if message_blocks == -1:
            slack_web_client.chat_postMessage(channel=click_event.channel.id,
                                              text=u"*검색결과가 없습니다.. 다시 입력해주세요*")
        else:
            slack_web_client.chat_postMessage(
                channel=click_event.channel.id,
                blocks=extract_json(message_blocks))
    elif func_Name == '2':
        message = _crawl_find_map(user_input)
        if message == -1:
            slack_web_client.chat_postMessage(
                channel=click_event.channel.id,
                text=u"띄워쓰기를 다시 하거나 좀 더 상세한 주소를 입력해 주세요.")
        else:
            slack_web_client.chat_postMessage(channel=click_event.channel.id,
                                              blocks=extract_json(message))
    elif func_Name in ["한식", "중식", "양식", "술집"]:
        message_blocks = make_sale_message_blocks(
            str(user_input) + " " + str(func_Name))
        slack_web_client.chat_postMessage(channel=click_event.channel.id,
                                          blocks=extract_json(message_blocks))

    # 메시지를 채널에 올립니다

    # Slack에게 클릭 이벤트를 확인했다고 알려줍니다
    return "OK", 200
コード例 #9
0
ファイル: chat.py プロジェクト: seongmink/RankingnewsChatbot
def on_button_click():
    # 버튼 클릭은 SlackEventsApi에서 처리해주지 않으므로 직접 처리합니다
    payload = request.values["payload"]

    click_event = MessageInteractiveEvent(json.loads(payload))

    cate = click_event.block_id
    new_date = click_event.value

    # 전날로 다시 크롤링합니다.
    message_blocks = _politics(cate, new_date)

    slack_web_client.chat_postMessage(channel=click_event.channel.id,
                                      text="요청한 " + new_date + " *" + cate +
                                      "* 뉴스입니다.\n")
    # 메시지를 채널에 올립니다
    slack_web_client.chat_postMessage(channel=click_event.channel.id,
                                      blocks=extract_json(message_blocks))

    # Slack에게 클릭 이벤트를 확인했다고 알려줍니다
    return "OK", 200
コード例 #10
0
ファイル: app.py プロジェクト: Kangmin93/chatbot_upload
def on_button_click():
    # 버튼 클릭은 SlackEventsApi에서 처리해주지 않으므로 직접 처리합니다
    payload = request.values["payload"]
    click_event = MessageInteractiveEvent(json.loads(payload))

    keyword = click_event.block_id
    item_name = click_event.value
    result = VitualEnv.get_6m_price_change_from_naver(item_name)

    if (result[0]):
        slack_web_client.chat_postMessage(
            channel=click_event.channel.id,
            text="저희가 선택하신 제품과 가장 유사한 제품의 가격변동 추이에요.\n 선택제품: {0} | 검색된 제품: {1}\n"
            .format(item_name, result[1]))
        slack_web_client.files_upload(channels=click_event.channel.id,
                                      file=result[2])
    else:
        slack_web_client.chat_postMessage(channel=click_event.channel.id,
                                          text=result[1])

    return "OK", 200
コード例 #11
0
ファイル: fortune.py プロジェクト: KMG0908/Fortune
def on_button_click():
    # 버튼 클릭은 SlackEventsApi에서 처리해주지 않으므로 직접 처리합니다
    payload = request.values["payload"]
    click_event = MessageInteractiveEvent(json.loads(payload))

    fortune = click_event.value
    user_id_ = click_event.user.id

    if(fortune == "birth"):
        message = today_fortune(user_id_)
        slack_web_client.chat_postMessage(
            channel=click_event.channel.id,
            blocks=extract_json(message)
        )
        return "OK", 200
    elif(fortune == "animal"):
        message = animal_fortune(user_id_)
        slack_web_client.chat_postMessage(
            channel=click_event.channel.id,
            blocks=extract_json(message)
        )
        return "OK", 200
    elif(fortune == "constellation"):
        message = constellation_fortune(user_id_)
        slack_web_client.chat_postMessage(
            channel=click_event.channel.id,
            blocks=extract_json(message)
        )
        return "OK", 200
    elif fortune in ["love", "money", "work", "study"]:
        message = today_fortune_detail(user_id_, fortune)
        slack_web_client.chat_postMessage(
            channel=click_event.channel.id,
            blocks=extract_json(message)
        )
        return "OK", 200

    # Slack에게 클릭 이벤트를 확인했다고 알려줍니다
    return "OK", 200
コード例 #12
0
ファイル: chatbot.py プロジェクト: Ungdoong/SSAStudy
def on_button_clicked():
    #유저 정보 읽어오기 및 변수 초기화
    user_list = load_CSV('user_list.csv')
    group_wait_list = load_CSV('group_wait_list.csv')
    pair_wait_list = load_CSV('pair_wait_list.csv')
    log = ''
    now = datetime.now()

    #페이로드 읽어오기
    payload = request.values["payload"]
    click_event = MessageInteractiveEvent(json.loads(payload))
    user_id = click_event.user.id
    action_id = click_event.action_id

    #로그 기록
    str_log = str(now) + '\t' + user_id + " " + action_id + " 선택"
    print(str_log)
    log += str_log + "\n"
    with open('log.txt', 'a') as log_file:
        log_file.write(log)

    #실행 위치에 따라 유저정보 업데이트
    if action_id == 'study_group':
        for user in user_list:
            if user.user_id == user_id and user.study_group == 1:
                action_id = 'already_group'
            elif user.user_id == user_id and user.study_group == 2:
                action_id = 'searching_group'
            elif user.user_id == user_id and user.study_group == 0:
                user.study_group = 2
            else:
                action_id = 'none_user'
        if not user_list:
            action_id = 'none_user'
    elif action_id == 'study_pair':
        for user in user_list:
            if user.user_id == user_id and user.study_pair == 1:
                action_id = 'already_pair'
            elif user.user_id == user_id and user.study_pair == 2:
                action_id = 'searching_pair'
            elif user.user_id == user_id and user.study_pair == 0:
                user.study_pair = 2
            else:
                action_id = 'none_user'
        if not user_list:
            action_id = 'none_user'
    elif action_id == 'already_group_yes':
        action_id = 'study_group'
        for user in user_list:
            if user.user_id == user_id and user.study_group == 1:
                user.study_group = 2
            else:
                return "OK", 200
        if not user_list:
            return "OK", 200
        #TODO : 같은 그룹원에게 메시지처리함수
    elif action_id == 'already_pair_yes':
        action_id = 'study_pair'
        for user in user_list:
            if user.user_id == user_id and user.study_pair == 1:
                user.study_pair = 2
            else:
                return "OK", 200
        if not user_list:
            return "OK", 200
        #TODO : 페어에게 메시지처리함수
    elif action_id == 'searching_group_yes':
        action_id = 'searching_stop'
        for user in user_list:
            if user.user_id == user_id and user.study_group == 2:
                user.study_group = 0
            else:
                return "OK", 200
        if not user_list:
            return "OK", 200
    elif action_id == 'searching_pair_yes':
        action_id = 'searching_stop'
        for user in user_list:
            if user.user_id == user_id and user.study_pair == 2:
                user.study_pair = 0
            else:
                return "OK", 200
        if not user_list:
            return "OK", 200
    elif action_id == 'already_group_no':
        return "OK", 200
    elif action_id == 'already_pair_no':
        return "OK", 200
    elif action_id == 'searching_group_no':
        return "OK", 200
    elif action_id == 'searching_pair_no':
        return "OK", 200
    else:
        topic = action_id
        user_list.append(User(user_id=user_id, topic=topic))

    category_blocks = _button_response(action_id, user_id)

    slack_web_client.chat_postMessage(channel=click_event.channel.id,
                                      blocks=extract_json(category_blocks))

    save_CSV('user_list.csv', user_list)

    return "OK", 200
コード例 #13
0
    def post(self, request, *args, **kwargs):
        try:
            json_data = json.loads(request.data['payload'])
            data = MessageInteractiveEvent(json_data)
            channel = data.channel.id
            game = caches['default'].get(channel)
            if not game:
                # Client.chat_postMessage(channel=channel, text="Can't find game?!?!")
                game = None

            else:
                game.player_list = game.player_list
                game.character_list = set(game.character_list)

                action_id = data.action_id
                username = (game.admin_user or data.user.name) if game.debug else data.user.name
                if action_id == 'action_join_game_lobby':
                    self.join_lobby(username, data.user.id, game)
                elif action_id == 'action_exit_game_lobby':
                    self.exit_lobby(username, game)
                elif action_id == 'start_game':
                    self.start_game(game)
                elif action_id == 'toggle_character':
                    self.toggle_character(data.value, game)
                elif action_id == 'toggle_quest_user':
                    self.toggle_quest_user(game, username, data.value)
                elif action_id == 'send_quest':
                    self.send_quest(game, username)
                elif action_id == 'approve_quest':
                    self.handle_vote(game, username, True)
                elif action_id == 'reject_quest':
                    self.handle_vote(game, username, False)
                elif action_id == 'succeed_quest':
                    self.handle_quest(game, username, True)
                elif action_id == 'fail_quest':
                    self.handle_quest(game, username, False)
                elif action_id == 'toggle_admin_act_as':
                    game.admin_user = data.value
                elif action_id == 'toggle_assassination_target':
                    self.handle_toggle_target(game, username, data.value)
                elif action_id == 'assassinate':
                    self.handle_assassinate(game, username)

                caches['default'].set(channel, game)

                if game.game_stage == GameStage.Lobby:
                    content = get_lobby_block_content(game)
                else:
                    content = get_game_board(game)

                push_new = action_id == 'push_down'
                if not push_new:
                    r = requests.post(url=data.response_url, json={'replace_original': True, 'blocks': content})
                else:
                    r = requests.post(url=data.response_url, json={'replace_original': False, 'blocks': []})
                    Client.chat_delete(channel=game.channel_id, ts=data.message_ts)
                    response = Client.chat_postMessage(channel=channel, blocks=content)
                    game.slack_message_ts = response.data['ts']
                    caches['default'].set(channel, game)
        except:
            print("exception caught")

        return Response(status=status.HTTP_200_OK)
コード例 #14
0
def on_button_click():
    payload = request.values["payload"]
    click_event = MessageInteractiveEvent(json.loads(payload))
    Thread(target=buttonText, args=(click_event, )).start()
    return "OK", 200
コード例 #15
0
ファイル: chatbot.py プロジェクト: Ungdoong/Slack_StudyBot
def on_button_clicked():
    #유저 정보 읽어오기 및 변수 초기화
    user_list = load_CSV('user_list.csv')
    group_list = load_CSV('group_list.csv')
    pair_list = load_CSV('pair_list.csv')
    group_wait_list = load_CSV('group_wait_list.csv')
    pair_wait_list = load_CSV('pair_wait_list.csv')
    group_matching_flag = False
    pair_matching_flag = False
    log = ''
    now = datetime.now()

    #페이로드 읽어오기
    payload = request.values["payload"]
    click_event = MessageInteractiveEvent(json.loads(payload))
    user_id = click_event.user.id
    action_id = click_event.action_id
    channel = click_event.channel.id

    #로그 기록
    str_log = str(
        now
    ) + '\t' + user_id + " " + action_id + " 선택 ( 채널 : " + channel + " )"
    print(str_log)
    log += str_log + "\n"
    with open('log.txt', 'a') as log_file:
        log_file.write(log)

    #실행 위치에 따라 유저정보 업데이트
    if action_id == 'study_group':
        for user in user_list:
            if user.user_id == user_id and user.study_group == 1:
                action_id = 'already_group'
                break
            elif user.user_id == user_id and user.study_group == 2:
                action_id = 'searching_group'
                break
            elif user.user_id == user_id and user.study_group == 0:
                user.study_group = 2
                group_wait_list.append(user)
                #TODO:그룹 매칭 함수
                group_wait_list, group_list, group_matching_flag \
                    = group_matching(group_wait_list, group_list)
                break
            action_id = 'none_user'
        if len(user_list) == 0:
            action_id = 'none_user'
    elif action_id == 'study_pair':
        for user in user_list:
            if user.user_id == user_id and user.study_pair == 1:
                action_id = 'already_pair'
                break
            elif user.user_id == user_id and user.study_pair == 2:
                action_id = 'searching_pair'
                break
            elif user.user_id == user_id and user.study_pair == 0:
                user.study_pair = 2
                pair_wait_list.append(user)
                #TODO:페어 매칭 함수
                pair_wait_list, pair_list, pair_matching_flag \
                    = pair_matching(pair_wait_list, pair_list)
                break
            action_id = 'none_user'
        if not user_list:
            action_id = 'none_user'
    elif action_id == 'already_group_yes':
        action_id = 'study_group'
        for user in user_list:
            if user.user_id == user_id and user.study_group == 1:
                user.study_group = 2
                group_wait_list.append(user)
                #TODO:그룹 매칭 함수
                group_wait_list, group_list, group_matching_flag \
                    = group_matching(group_wait_list, group_list)
                break
            else:
                return "OK", 200
        if not user_list:
            return "OK", 200
        #TODO : 같은 그룹원에게 메시지처리함수
        #그룹 서칭
        for group in group_list:
            for member in group:
                if user_id == member.user_id:
                    breaked_group = group
        #그룹원에게 메시지
        for index in range(len(group)):
            matching_blocks = _matching_breaking("group", breaked_group)
            slack_web_client.chat_postMessage(
                channel=breaked_group[index].channel_id,
                blocks=extract_json(matching_blocks))
    elif action_id == 'already_pair_yes':
        action_id = 'study_pair'
        for user in user_list:
            if user.user_id == user_id and user.study_pair == 1:
                user.study_pair = 2
                for i in range(len(pair_list)):
                    if pair_list[i].user_id == user_id:
                        pair_list.pop(i)
                        break
                pair_wait_list.append(user)
                #TODO:페어 매칭 함수
                pair_wait_list, pair_list, pair_matching_flag \
                    = pair_matching(pair_wait_list, pair_list)
                break
            else:
                return "OK", 200
        if not user_list:
            return "OK", 200
        #TODO : 페어에게 메시지처리함수
        for pair in pair_list:
            for member in pair:
                if user_id == member.user_id:
                    breaked_pair = pair
                    break
        #그룹원에게 메시지
        for index in range(len(pair)):
            matching_blocks = _matching_breaking("pair", breaked_pair)
            slack_web_client.chat_postMessage(
                channel=breaked_pair[index].channel_id,
                blocks=extract_json(matching_blocks))
    elif action_id == 'searching_group_yes':
        action_id = 'searching_stop'
        for user in user_list:
            if user.user_id == user_id and user.study_group == 2:
                user.study_group = 0
            else:
                return "OK", 200
        if not user_list:
            return "OK", 200
    elif action_id == 'searching_pair_yes':
        action_id = 'searching_stop'
        for user in user_list:
            if user.user_id == user_id and user.study_pair == 2:
                user.study_pair = 0
            else:
                return "OK", 200
        if not user_list:
            return "OK", 200
    elif action_id == 'already_group_no':
        return "OK", 200
    elif action_id == 'already_pair_no':
        return "OK", 200
    elif action_id == 'searching_group_no':
        return "OK", 200
    elif action_id == 'searching_pair_no':
        return "OK", 200
    else:
        topic = action_id
        already_user = False
        if len(user_list) > 0:
            for user in user_list:
                if user_id == user.user_id:
                    user.topic = topic
                    already_user = True
                    break
        if already_user == False:
            user_list.append(
                User(user_id=user_id, channel_id=channel, topic=topic))

    category_blocks = _button_response(action_id, user_id)

    slack_web_client.chat_postMessage(channel=click_event.channel.id,
                                      blocks=extract_json(category_blocks))

    if group_matching_flag:
        matched_group = group_list[len(group_list) - 1]
        matching_blocks = _matching_success("group", matched_group)
        slack_web_client.chat_postMessage(channel=channel,
                                          blocks=extract_json(matching_blocks))
    elif pair_matching_flag:
        matched_pair = pair_list[len(pair_list) - 1]
        matching_blocks = _matching_success("pair", matched_pair)
        slack_web_client.chat_postMessage(channel=channel,
                                          blocks=extract_json(matching_blocks))

    save_CSV('user_list.csv', user_list)
    save_CSV('group_list.csv', group_list)
    save_CSV('pair_list.csv', pair_list)
    save_CSV('group_wait_list.csv', group_wait_list)
    save_CSV('pair_wait_list.csv', pair_wait_list)

    return "OK", 200