@php use Carbon\Carbon; use Illuminate\Support\Str; $tz = config('app.timezone', 'Asia/Tokyo'); $searchQ = $lineChatSearchQuery ?? ''; $friends = $lineChatFriends ?? collect(); $timeline = $lineChatTimeline ?? collect(); $selectedUid = $lineChatSelectedLineUserId; $selectedSub = $lineChatSelectedSubscriber; $selectedRow = $friends->first(fn (array $row) => (string) $row['line_user_id'] === (string) $selectedUid); $selectedDisplayName = is_array($selectedRow) ? (string) ($selectedRow['display_name'] ?? 'LINEユーザー') : 'LINEユーザー'; $selectedAvatarUrl = is_array($selectedRow) ? ($selectedRow['avatar_url'] ?? null) : null; $lineBotPictureUrl = $lineBotPictureUrl ?? null; $lineBotDisplayName = $lineBotDisplayName ?? null; $botInitial = Str::upper(Str::substr(trim((string) ($lineBotDisplayName ?: 'BOT')), 0, 1)); $chatHref = function (?string $uid = null) use ($account, $scenario, $searchQ) { $params = ['account' => $account, 'scenario' => $scenario, 'slug' => 'line-chat']; $qs = array_filter([ 'u' => $uid, 'q' => $searchQ !== '' ? $searchQ : null, ], fn ($v) => $v !== null && $v !== ''); $url = route('scenario.workspace.show', $params); if ($qs !== []) { $url .= '?'.http_build_query($qs); } return $url; }; @endphp @push('styles') @endpush @include('account.scenario.partials._line_webhook_delivery_alert', ['lineAccount' => $lineAccount ?? null])

LINEチャット

@csrf

左は Webhook で届いた user を最終メッセージ順に並べ、Messaging API でプロフィール(表示名・アイコン)を反映します。右は Webhook で届いたイベント(フォロー・受信メッセージ)と、monaka からの送信ログ(Messaging API push)および公式・別ツールで送った内容を手入力で残した記録です。LINE公式の画面だけで送った文面は Webhook に載らないため自動では出ませんが、下の「外部送信を記録」で時刻・本文を登録するとタイムラインに並びます。未読・ピン止めは準備中です。

@forelse($friends as $row) @php $uid = (string) $row['line_user_id']; $lastAt = $row['last_at']; $displayName = (string) ($row['display_name'] ?? 'LINEユーザー'); $avatarUrl = $row['avatar_url'] ?? null; $initial = Str::upper(Str::substr(trim($displayName ?: '?'), 0, 1)); $isActive = $selectedUid === $uid; @endphp
{{ $displayName }}
{{ $row['preview'] }}
@if($lastAt)
{{ $lastAt->timezone($tz)->format('m/d') }}
@endif
@empty @php $lineAccountLinked = isset($lineAccount) && $lineAccount instanceof \App\Models\DeliveryAccount; $subsTotal = (int) $scenario->subscribers()->count(); $subsWithLine = (int) $scenario->subscribers()->countableForLine()->count(); @endphp
@if(! $lineAccountLinked)

このシナリオに LINEアカウントが紐づいていません。シナリオ設定で LINE を選ぶか、作成時に LINE を紐づけてください。

@else

一覧に出る条件

  • 読者に LINE user ID がある(LINE登録・友だち追加の Webhook など)
  • または、公式アカウントへ メッセージ・友だち追加があり Webhook で monaka に届いた
@if($subsTotal > 0 && $subsWithLine === 0)

読者は {{ $subsTotal }} 人いますが メール登録のみです(一覧の「LINE」が 0 のとき)。LINE からメッセージを送るか、LINE 登録ページから登録してください。

@elseif($subsTotal === 0) @php $officialFollowers = isset($lineAccount) && $lineAccount instanceof \App\Models\DeliveryAccount ? $lineAccount->line_followers_count : null; @endphp @if($officialFollowers !== null && (int) $officialFollowers > 0)

LINE 公式では友だち {{ number_format((int) $officialFollowers) }} 人ですが、monaka にはまだ届いていません。

@else

このシナリオの読者は 0 人です。

@endif

右上の LINE公式の友だちを取り込む を押すか、LINE からメッセージを送ってください。

@else

まだトーク履歴がありません。右上の 取り込む か、LINE からメッセージを送ってください。

@endif @endif
@endforelse
@if($friends->isEmpty())
左の一覧に表示する友だちがありません。
@elseif($selectedUid)
@if($selectedAvatarUrl) @endif {{ $selectedDisplayName }}
@forelse($timeline as $item) @php $kind = $item['kind']; $atFmt = $item['at']->timezone($tz)->format('m/d H:i'); $friendInitial = Str::upper(Str::substr(trim($selectedDisplayName ?: '?'), 0, 1)); @endphp @if($kind === 'system')
{{ $item['text'] }}
@elseif($kind === 'incoming')
{!! nl2br(e((string) $item['text'])) !!}
{{ $atFmt }}
@else
@if(!empty($item['label']))
{{ $item['label'] }}
@endif
{!! nl2br(e((string) $item['text'])) !!}
{{ $atFmt }}
@endif @empty
この友だちとのトーク履歴がありません。
@endforelse
@csrf @if($searchQ !== '') @endif
@error('body')
{{ $message }}
@enderror
公式・別ツールで送った内容を手入力で記録

LINE 公式の応答メッセージなど Webhook に載らない送信は、ここで送信日時・本文を残すと右のタイムラインに出ます(実際の LINE 送信は行いません)。

@csrf @if($searchQ !== '') @endif
@error('sent_at')
{{ $message }}
@enderror
@error('body_text')
{{ $message }}
@enderror
@else
左から友だちを選択してください。
@endif
@if($selectedUid) @push('scripts') @endpush @endif