[LINE WORKS version Trello Bot] How to create a private talk room including a talk bot

Good evening, this is @ 0yan. I wrote the following articles about the LINE WORKS version of Trello Bot in the past.

** [Past Articles] **

  1. The story of making a LINE WORKS version of Trello Bot with Python
  2. Until deploy Trello Bot for LINE WORKS on Heroku
  3. [Note] Implementation of LINE WORKS version Trello Bot by Python (PyPI lineworks installation Ver.)

However, when I tried to make a Trello Bot dedicated to that section at the request of another department, I couldn't understand "What? How should I make a private talk room including a talk bot ...?" (In short) I forgot).

Perhaps those who read the above article will want to receive ** notifications of updates to the Trello board shared by specific members (you want to create a private talk room) **, so this time I'll read that article. I would like to write.

Prerequisites

--LINE WORKS API information acquired (Reference: Preparation for API authentication) --Trello API information acquired (Reference: [Note] Trello Webhook related)

environment

Library

Creating a Trello Bot

Follow the same procedure as in past article 3

  1. Coding
  2. Deploy to Heroku via GitHub
  3. Create a Trello Webhook To do.

If the notification destination of the talk bot is a specific individual, it is OK if you enter the account ID of that individual in the Heroku environment variable "ACCOUNT_ID", but if the notification destination of the talk bot is a private talk room, do the following work I will.

When the notification destination of the talk bot is a private talk room

① Modify the source code

The code below is the code written in the above coding. Enter the account ID (~ @ domain name) of the member of the private talk room to be created in the element "Arbitrary account ID" in the list to be assigned to the variable ʻaccount_ids of create_room () . Also, enter the display name of the private talk room in the argument "Arbitrary talk room name" of the function talkbot.create_room ()to be assigned to the variableres of create_room () `.

app.py


# coding: utf-8

import os

from flask import Flask, abort, request
from lineworks.talkbot_api import TalkBotApi


app = Flask(__name__)
talkbot = TalkBotApi(
    api_id=os.environ.get('API_ID'),
    private_key=os.environ.get('PRIVATE_KEY'),
    server_api_consumer_key=os.environ.get('SERVER_API_CONSUMER_KEY'),
    server_id=os.environ.get('SERVER_ID'),
    bot_no=os.environ.get('BOT_NO'),
    account_id=os.environ.get('ACCOUNT_ID'),
    room_id=os.environ.get('ROOM_ID'),
    domain_id=os.environ.get('DOMAIN_ID')
)


@app.route('/')
def index():
    return 'Start', 200


@app.route('/webhook', methods=['GET', 'HEAD', 'POST'])
def webhook():
    if request.method == 'GET':
        return 'Start', 200
    elif request.method == 'HEAD':
        return '', 200
    elif request.method == 'POST':
        action_type = request.json['action']['display']['translationKey']
        if action_type == 'action_comment_on_card':
            card_name = request.json['action']['data']['card']['name']
            user_name = request.json['action']['memberCreator']['fullName']
            comment = request.json['action']['data']['text']
            message = user_name + "Commented.\n [card]" + card_name + "\n [Comment]" + comment
            talkbot.send_text_message(send_text=message)
            return '', 200
        else:
            pass
    else:
        abort(400)


@app.route('/create_room', methods=['GET'])
def create_room():
    if request.method == 'GET':
        account_ids = [
            "Any account ID",
            "Any account ID",
            "Any account ID",
            "Any account ID",
            "Any account ID"
        ]
        res = talkbot.create_room(account_ids=account_ids, title="Any talk room name (eg Trello Bot)")
        return res, 200
    else:
        abort(400)        
        

if __name__ == '__main__':
    app.run()
② Create a private talk room including Trello Bot and get a room ID

https://{Herokuのアプリ名}.herokuapp.com/create_room When you access the above URL, the room ID will be returned as an HTTP response (the following room ID will be displayed in the browser).

{
  "roomId": "123456"
}
③ Enter the room ID in the environment variable of Heroku

Enter the room ID obtained in ② in the environment variable "ROOM_ID" on Heroku. At this time, don't forget to delete the Heroku environment variable "ACCOUNT_ID".

④ Test

Try commenting on Trello's card. You will receive a Trello update notification with the talk room name specified in ②.

in conclusion

Thank you for visiting. I hope LINE WORKS will continue to grow!

Recommended Posts

[LINE WORKS version Trello Bot] How to create a private talk room including a talk bot
How to create a Kivy 1-line input box
How to create a Conda package
How to create a virtual bridge
How to create a Dockerfile (basic)
How to create a config file
Create a LINE Bot in Django
Create a bot to retweet coronavirus information
How to create a git clone folder
[Python] [LINE Bot] Create a parrot return LINE Bot
How to create a repository from media
How to send a message to LINE with curl
How to create a Python virtual environment (venv)
How to create a function object from a string
Create a LINE BOT with Minette for Python
How to create a JSON file in Python
Steps to create a Twitter bot with python
How to create a shortcut command for LINUX
How to create a multi-platform app with kivy
Make a LINE WORKS bot with Amazon Lex
[Note] How to create a Mac development environment
The world's most easy-to-understand explanation of how to make a LINE BOT (1) [Account preparation]
Read the Python-Markdown source: How to create a parser
[AWS] I made a reminder BOT with LINE WORKS
How to create an article from the command line
[Python] How to draw a line graph with Matplotlib
How to create a submenu with the [Blender] plugin
[Go] How to create a custom error for Sentry
How to create a local repository for Linux OS
How to create a simple TCP server / client script
How to create a kubernetes pod from python code
How to make an interactive LINE BOT 004 (answer the closing date of a listed company)
Create a slack bot
How to make a Cisco Webex Teams BOT with Flask
[Go language] Try to create a uselessly multi-threaded line counter
How to install NPI + send a message to line with python
Make a LINE bot with GoogleAppEngine / py. Simple naked version
Create a Mastodon bot with a function to automatically reply with Python
How to generate a public key from an SSH private key
[Python Kivy] How to create a simple pop up window
I want to send a message from Python to LINE Bot
How to create a SAS token for Azure IoT Hub
I tried to create a bot for PES event notification
[AWS] I made a reminder BOT with LINE WORKS (implementation)
Create an automatic grade management app for Tenhou private room with LINE bot and Python Part 1
Create an automatic grade management app for Tenhou private room with LINE bot and Python Part 2
Create an automatic grade management app for Tenhou private room with LINE bot and Python Part ③