Skip to content

Commit

Permalink
Merge pull request #62 from conglinyizhi/main
Browse files Browse the repository at this point in the history
新增:将飞书 Webhook 推送更改为卡片样式
  • Loading branch information
JimmyLv authored Mar 22, 2023
2 parents 60b1ff6 + 3416342 commit 97d41ff
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 27 deletions.
4 changes: 2 additions & 2 deletions components/ActionsAfterResult.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export function ActionsAfterResult({
}) {
const [flomoWebhook] = useLocalStorage<string>('user-flomo-webhook')
const [larkWebhook] = useLocalStorage<string>('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 (
Expand Down
4 changes: 2 additions & 2 deletions hooks/notes/flomo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down
69 changes: 49 additions & 20 deletions hooks/notes/lark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 16 additions & 3 deletions utils/formatSummary.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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) {
Expand Down

0 comments on commit 97d41ff

Please sign in to comment.