日本時間5月16日のContent Cloud Summitで、カスタムアプリにBox AI APIを活用する方法を紹介します。

詳細を表示

コメントの作成

ガイド コメント コメントの作成

コメントの作成

コメントを作成するには、コメントのメッセージと、コメントを残すファイルのIDを指定してPOST /comments APIを呼び出します。

cURL
curl -i -X POST "https://api.box.com/2.0/comments" \
     -H "authorization: Bearer <ACCESS_TOKEN>" \
     -H "content-type: application/json" \
     -d '{
       "message": "Review completed!",
       "item": {
         "type": "file",
         "id": 426436
       }
     }'
.NET
var requestParams = new BoxCommentRequest()
{
    Item = new BoxRequestEntity()
    {
        Type = BoxType.File,
        Id = "12345"
    },
    Message = "Great work!"
};
BoxComment comment = await client.CommentsManager.AddCommentAsync(requestParams);
Java
BoxFile file = new BoxFile(api, "id");
file.addComment("This file is pretty cool.");
Python
comment = client.file(file_id='11111').add_comment('When should I have this done by?')
Node
client.comments.create('33333', 'Is this the latest version?')
    .then(comment => {
        /* comment -> {
            type: 'comment',
            id: '11111',
            is_reply_comment: false,
            message: 'Is this the latest version?',
            created_by: 
            { type: 'user',
                id: '22222',
                name: 'Example User',
                login: 'user@example.com' },
            created_at: '2012-12-12T11:25:01-08:00',
            item: { id: '33333', type: 'file' },
            modified_at: '2012-12-12T11:25:01-08:00' }
        */
    });
iOS
client.comments.create(
    itemId: "11111",
    itemType: "file",
    message: "Thanks!"
) { (result: Result<Comment, BoxSDKError>) in
    guard case let .success(comment) = result else {
        print("Error creating comment")
        return
    }

    print("Added comment to \(comment.item.name): \"\(comment.message)\"")
}

コメントのメッセージでは、@記号を使用してユーザーをメンションすることもできます。そのためには、メッセージ内の任意の場所に@[userid:name]という文字列を追加します。user_idはターゲットユーザーのIDで、nameには任意のカスタムフレーズを使用できます。Box UIでは、この名前がユーザーのプロフィールにリンクされます。

次に、この文字列をmessageではなくtagged_messageとして渡します。

cURL
curl -i -X POST "https://api.box.com/2.0/comments" \
     -H "authorization: Bearer <ACCESS_TOKEN>" \
     -H "content-type: application/json" \
     -d '{
       "tagged_message": "What do you think @[1234:John]?",
       "item": {
         "type": "file",
         "id": 123
       }
     }
Java
BoxFile file = new BoxFile(api, "id");
file.addComment("Message mentioning @[1234:user@box.com].");
Python
comment = client.file(file_id='11111').add_comment('Hey @[44444:boss], when should I have this done by?')
Node
client.comments.createTaggedComment('33333', '@[23560:Bob] Is this the latest version?')
    .then(comment => {
        /* comment -> {
            type: 'comment',
            id: '11111',
            is_reply_comment: false,
            tagged_message: '@[23560:Bob] Is this the latest version?',
            created_by: 
            { type: 'user',
                id: '22222',
                name: 'Example User',
                login: 'user@example.com' },
            created_at: '2012-12-12T11:25:01-08:00',
            item: { id: '33333', type: 'file' },
            modified_at: '2012-12-12T11:25:01-08:00' }
        */
    });