diff --git a/components/ActionsAfterResult.tsx b/components/ActionsAfterResult.tsx index 5abb5c93..1e95cb15 100644 --- a/components/ActionsAfterResult.tsx +++ b/components/ActionsAfterResult.tsx @@ -16,8 +16,8 @@ export function ActionsAfterResult({ }) { const [flomoWebhook] = useLocalStorage('user-flomo-webhook') const [larkWebhook] = useLocalStorage('user-lark-webhook') - const { loading: flomoLoading, save: flomoSave } = useSaveToFlomo(summaryNote, flomoWebhook || '') - const { loading: larkLoading, save: larkSave } = useSaveToLark(summaryNote, larkWebhook || '') + const { loading: flomoLoading, save: flomoSave } = useSaveToFlomo(summaryNote, curVideo, flomoWebhook || '') + const { loading: larkLoading, save: larkSave } = useSaveToLark(summaryNote, curVideo, larkWebhook || '') const hasNoteSetting = flomoWebhook || larkWebhook return ( diff --git a/hooks/notes/flomo.ts b/hooks/notes/flomo.ts index c9801855..8a3daec7 100644 --- a/hooks/notes/flomo.ts +++ b/hooks/notes/flomo.ts @@ -2,7 +2,7 @@ import { useState } from 'react' import { useAnalytics } from '~/components/context/analytics' import { useToast } from '~/hooks/use-toast' -export function useSaveToFlomo(note: string, webhook: string) { +export function useSaveToFlomo(note: string, video: string, webhook: string) { const [loading, setLoading] = useState(false) const { toast } = useToast() const { analytics } = useAnalytics() @@ -15,7 +15,7 @@ export function useSaveToFlomo(note: string, webhook: string) { 'Content-Type': 'application/json', }, body: JSON.stringify({ - content: note + '\n#BibiGpt', + content: `${note}\n\n原视频:${video}\n#BibiGpt`, }), }) const json = await response.json() diff --git a/hooks/notes/lark.ts b/hooks/notes/lark.ts index c2fa9fcc..5510de23 100644 --- a/hooks/notes/lark.ts +++ b/hooks/notes/lark.ts @@ -2,37 +2,66 @@ import { useState } from 'react' import { useAnalytics } from '~/components/context/analytics' import { useToast } from '~/hooks/use-toast' -export default function useSaveToLark(note: string, webhook: string) { +export default function useSaveToLark(note: string, video: string, webhook: string) { const [loading, setLoading] = useState(false) const { toast } = useToast() const { analytics } = useAnalytics() const save = async () => { + const larkCardData = { + msg_type: 'interactive', + card: { + elements: [ + { + tag: 'div', + text: { + content: note, + tag: 'plain_text', + }, + }, + { + tag: 'note', + elements: [ + { + tag: 'plain_text', + content: `原视频:${video}`, + }, + ], + }, + { + tag: 'action', + actions: [ + { + tag: 'button', + text: { + tag: 'plain_text', + content: '观看视频', + }, + type: 'primary', + multi_url: { + url: video, + }, + }, + ], + }, + ], + header: { + template: 'blue', + title: { + content: 'BibiGPT 视频摘要', + tag: 'plain_text', + }, + }, + }, + } setLoading(true) + console.log(note) const response = await fetch(webhook, { method: 'POST', headers: { 'Content-Type': 'application/json', }, - body: JSON.stringify({ - msg_type: 'post', - content: { - post: { - zh_cn: { - title: 'BibiGPT 总结', - content: [ - [ - { - tag: 'text', - text: note.substring(1), - // but why - }, - ], - ], - }, - }, - }, - }), + body: JSON.stringify(larkCardData), }) const json = await response.json() console.log('========response========', json) diff --git a/utils/formatSummary.ts b/utils/formatSummary.ts index 064da3a3..1ec7de56 100644 --- a/utils/formatSummary.ts +++ b/utils/formatSummary.ts @@ -1,7 +1,20 @@ import { extractSentenceWithTimestamp } from '~/utils/extractSentenceWithTimestamp' import { extractTimestamp } from '~/utils/extractTimestamp' -export function formatSummary(summary: string) { +/** + * a summary generated by ChatGPT + * + * @export + * @param {string} summary + * @return {*} {{ + * summaryArray: string[], + * formattedSummary: string + * }} + */ +export function formatSummary(summary: string): { + summaryArray: string[] + formattedSummary: string +} { /* if (shouldShowTimestamp) { try { @@ -23,8 +36,8 @@ export function formatSummary(summary: string) { } */ - const summaryArray = ('\n' + summary).split('\n- ') - const formattedSummary = summaryArray + const summaryArray: string[] = summary.split('\n- ') + const formattedSummary: string = summaryArray .map((s) => { const matchTimestampResult = extractSentenceWithTimestamp(s) if (matchTimestampResult) {