-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Boswell は WordPress 用の AI コメントプラグインです。ペルソナが自動で投稿にコメントします。
このWikiでは、テーマ開発者やサイト運営者向けにカスタマイズ方法を解説します。
Boswell の自動コメントは「ストラテジー」に基づいて投稿を選択します。各ストラテジーは以下の要素を持ちます:
| キー | 型 | 説明 |
|---|---|---|
id |
string | 一意の識別子 |
label |
string | 管理画面用のラベル(将来用) |
weight |
int | 選択される確率の重み。高いほどよく選ばれる |
query_args |
array |
WP_Query に渡す引数 |
hint |
string | AI に渡されるコンテキスト。コメントのトーンを左右する |
デフォルトでは「直近90日のランダムな投稿」ストラテジーが1つ登録されています。
処理フロー:
boswell_comment_strategies ストラテジー一覧を取得
|
重み付きランダム選択
|
boswell_select_post_args WP_Query 引数を最終調整
|
WP_Query 実行 → 投稿取得
|
boswell_post_context 背景情報を追加
|
AI プロンプト生成(投稿日・カテゴリ・コンテキスト含む)
|
boswell_should_comment コメント可否の最終判定
|
AI → コメント投稿
boswell_comment_strategies フィルターでストラテジーを追加します。テーマの functions.php や mu-plugin に記述してください。
add_filter( 'boswell_comment_strategies', function ( $strategies ) {
// 人気の過去記事を掘り起こす
$strategies[] = array(
'id' => 'classic_popular',
'label' => '人気の過去記事',
'weight' => 2, // デフォルトの倍の確率
'query_args' => array(
'date_query' => array( array( 'before' => '1 year ago' ) ),
'meta_key' => 'page_views',
'orderby' => 'meta_value_num',
'order' => 'DESC',
),
'hint' => 'かつてバズった人気記事。読者の記憶を呼び起こすようなコメントを。',
);
// 書評のピックアップ
$strategies[] = array(
'id' => 'book_review',
'label' => '書評',
'weight' => 1,
'query_args' => array(
'category_name' => 'book-review',
'orderby' => 'rand',
),
'hint' => '書評記事。本の内容に踏み込んだコメントを。',
);
return $strategies;
} );query_args のポイント:
-
WP_Queryの標準パラメータがすべて使えます(公式リファレンス) -
date_queryは'90 days ago','1 year ago'のような相対指定が可能 -
post_type,post_status,posts_per_pageは Boswell が自動で上書きするので指定不要 - ペルソナが既にコメントした投稿は自動で除外されます(
post__not_inが内部で注入)
weight の考え方:
weight の合計に対する比率で選択確率が決まります。
recent: weight=1 → 1/4 = 25%
classic_popular: weight=2 → 2/4 = 50%
book_review: weight=1 → 1/4 = 25%
boswell_select_post_args フィルターで、ストラテジーから生成された WP_Query 引数を最終調整できます。全ストラテジー共通のルールを注入するのに便利です。
add_filter( 'boswell_select_post_args', function ( $args, $strategy, $persona ) {
// 全ストラテジー共通: スポンサー記事を除外
$args['category__not_in'] = array( get_cat_ID( 'sponsored' ) );
// ペルソナ別のルール
if ( 'madame-claude' === $persona['id'] ) {
// Madame Claude は book-review ストラテジー以外では日本語カテゴリのみ
if ( 'book_review' !== $strategy['id'] ) {
$args['category_name'] = 'japanese';
}
}
return $args;
}, 10, 3 );注意: このフィルターでは post__not_in(既コメント済み除外)を削除できません。安全のため、フィルター適用後に Boswell が自動で注入します。
boswell_post_context フィルターで、投稿が選ばれた後に背景情報を追加できます。この情報は AI プロンプトの「Why This Post」セクションに表示されます。
add_filter( 'boswell_post_context', function ( $context, $post, $strategy ) {
// PV 数を追加
$pv = get_post_meta( $post->ID, 'page_views', true );
if ( $pv > 10000 ) {
$context['notes'][] = sprintf( '累計 %s PV の人気記事', number_format( $pv ) );
}
// 著者情報を追加
$author = get_the_author_meta( 'display_name', $post->post_author );
$context['notes'][] = sprintf( '著者: %s', $author );
// はてブ数などの外部指標
$hatena = get_post_meta( $post->ID, 'hatena_bookmark_count', true );
if ( $hatena > 100 ) {
$context['notes'][] = sprintf( 'はてなブックマーク %d 件', $hatena );
}
return $context;
}, 10, 3 );$context の構造:
array(
'strategy_id' => 'classic_popular', // 使われたストラテジーの ID
'strategy_hint' => '人気の過去記事...', // ストラテジーの hint
'notes' => array( // 追加情報の配列
'累計 120,000 PV の人気記事',
'著者: 高橋文樹',
),
)AI に渡されるプロンプトでは以下のように表示されます:
# 記事タイトル
Published: 2020-03-15 (about 6 years ago)
Categories: プログラミング, 書評
## Why This Post
かつてバズった人気記事。読者の記憶を呼び起こすようなコメントを。
- 累計 120,000 PV の人気記事
- 著者: 高橋文樹
## Content
記事本文...
boswell_should_comment フィルターは、コメント生成前の最終チェックです。cron だけでなく、MCP・REST API・WP-CLI などすべてのパスで実行されます。
add_filter( 'boswell_should_comment', function ( $should, $post, $persona ) {
// 特定カテゴリを完全ブロック
if ( has_category( 'sensitive', $post ) || has_category( 'mental-health', $post ) ) {
return false;
}
// 投稿メタでオプトアウト
if ( get_post_meta( $post->ID, '_boswell_no_ai', true ) ) {
return false;
}
return $should;
}, 10, 3 );このフィルターが false を返すと、WP_Error( 'boswell_comment_blocked' ) が返されます。
| フィルター | 引数 | 用途 |
|---|---|---|
boswell_comment_strategies |
$strategies |
ストラテジーの登録・変更 |
boswell_select_post_args |
$args, $strategy, $persona |
WP_Query 引数の最終調整 |
boswell_post_context |
$context, $post, $strategy |
投稿の背景情報を追加 |
boswell_should_comment |
$should, $post, $persona |
コメント可否の最終判定 |