Good evening, this is @ 0yan. I wrote the following articles about the LINE WORKS version of Trello Bot in the past.
** [Past Articles] **
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.
--LINE WORKS API information acquired (Reference: Preparation for API authentication) --Trello API information acquired (Reference: [Note] Trello Webhook related)
Follow the same procedure as in past article 3
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.
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 variable
res 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()
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 obtained in ② in the environment variable "ROOM_ID" on Heroku. At this time, don't forget to delete the Heroku environment variable "ACCOUNT_ID".
Try commenting on Trello's card. You will receive a Trello update notification with the talk room name specified in ②.
Thank you for visiting. I hope LINE WORKS will continue to grow!
Recommended Posts