-
-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1081 from The-Commit-Company/1071-documentation-r…
…equest-step-by-step-guide-for-using-raven-bot feat: inline docs for Raven Bots
- Loading branch information
Showing
5 changed files
with
207 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
frontend/src/components/feature/settings/ai/bots/BotDocs.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import CodeBlock from '@/components/layout/CodeBlock' | ||
import { Stack } from '@/components/layout/Stack' | ||
import { RavenBot } from '@/types/RavenBot/RavenBot' | ||
import { Code, Heading, Text } from '@radix-ui/themes' | ||
import { useFormContext } from 'react-hook-form' | ||
|
||
const BotDocs = () => { | ||
|
||
const { getValues } = useFormContext<RavenBot>() | ||
|
||
const bot_id = getValues('name') | ||
|
||
const botVarName = bot_id.replace(/-/g, '_') | ||
|
||
const SectionHeading = ({ children }: { children: React.ReactNode }) => { | ||
return <Heading as='h3' size='3' className='not-cal' weight='medium'>{children}</Heading> | ||
} | ||
|
||
const Paragraph = ({ children }: { children: React.ReactNode }) => { | ||
return <Text as='p' size='2' color='gray'>{children}</Text> | ||
} | ||
|
||
const codeSamples = { | ||
sendMessage: `${botVarName} = frappe.get_doc("Raven Bot", "${bot_id}") | ||
# Send a message to a channel. Text can be in HTML format. | ||
${botVarName}.send_message(channel_id="channel-name", text="This is a test message.")`, | ||
|
||
sendMessageInMarkdown: `${botVarName}.send_message( | ||
channel_id="channel-name", | ||
text="This is a test message.", | ||
markdown=True | ||
)`, | ||
|
||
sendMessageWithDocumentLink: `${botVarName}.send_message( | ||
channel_id="channel-name", | ||
text="This is a test message.", | ||
link_doctype="DocType", | ||
link_document="Document Name" | ||
)`, | ||
|
||
sendDirectMessage: `${botVarName}.send_direct_message( | ||
user_id="[email protected]", | ||
text="This is a test message." | ||
)` | ||
} | ||
|
||
return ( | ||
<Stack gap='3' pt='2'> | ||
<Text as='p' size='3'> | ||
The following code samples show how to use the bot in a Frappe app or Server Script. | ||
</Text> | ||
<Stack gap='0'> | ||
<Stack gap='1'> | ||
<SectionHeading> | ||
Sending a message to a channel | ||
</SectionHeading> | ||
<Paragraph> | ||
Bots can be used to send messages to channels with html formatted content. | ||
</Paragraph> | ||
</Stack> | ||
<CodeBlock | ||
code={codeSamples.sendMessage} | ||
/> | ||
</Stack> | ||
<Stack gap='0'> | ||
<Stack gap='1'> | ||
<SectionHeading> | ||
Sending a message to a channel in markdown format | ||
</SectionHeading> | ||
<Paragraph> | ||
You can send markdown formatted text to a channel by setting the <Code>markdown</Code> parameter to True. | ||
</Paragraph> | ||
</Stack> | ||
<CodeBlock | ||
code={codeSamples.sendMessageInMarkdown} | ||
/> | ||
</Stack> | ||
|
||
<Stack gap='0'> | ||
<Stack gap='1'> | ||
<SectionHeading> | ||
Sending a message with a document link | ||
</SectionHeading> | ||
<Paragraph> | ||
You can send a message with a link to any document in the system by setting the <Code>link_doctype</Code> and <Code>link_document</Code> parameters. | ||
</Paragraph> | ||
</Stack> | ||
<CodeBlock | ||
code={codeSamples.sendMessageWithDocumentLink} | ||
/> | ||
</Stack> | ||
<Stack gap='0'> | ||
<Stack gap='1'> | ||
<SectionHeading> | ||
Sending a direct message to a user | ||
</SectionHeading> | ||
<Paragraph> | ||
You can send a direct message to a user by calling the <Code>send_direct_message</Code> method and setting the user_id parameter. | ||
This method also accepts markdown and document link parameters. | ||
</Paragraph> | ||
</Stack> | ||
<CodeBlock | ||
code={codeSamples.sendDirectMessage} | ||
/> | ||
</Stack> | ||
</Stack> | ||
) | ||
} | ||
|
||
export default BotDocs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { EditorContent, useEditor } from '@tiptap/react' | ||
import CodeBlockLowlight from '@tiptap/extension-code-block-lowlight' | ||
import { common, createLowlight } from 'lowlight' | ||
import python from 'highlight.js/lib/languages/python' | ||
import css from 'highlight.js/lib/languages/css' | ||
import js from 'highlight.js/lib/languages/javascript' | ||
import ts from 'highlight.js/lib/languages/typescript' | ||
import html from 'highlight.js/lib/languages/xml' | ||
import json from 'highlight.js/lib/languages/json' | ||
import StarterKit from '@tiptap/starter-kit' | ||
import '@/components/feature/chat/ChatInput/tiptap.styles.css' | ||
import { IconButton, Tooltip } from '@radix-ui/themes' | ||
import { BiClipboard, BiCopy } from 'react-icons/bi' | ||
import { toast } from 'sonner' | ||
|
||
const lowlight = createLowlight(common) | ||
lowlight.register('python', python) | ||
lowlight.register('css', css) | ||
lowlight.register('js', js) | ||
lowlight.register('ts', ts) | ||
lowlight.register('html', html) | ||
lowlight.register('json', json) | ||
|
||
|
||
type Props = { | ||
code: string, | ||
} | ||
|
||
const CodeBlock = ({ code }: Props) => { | ||
|
||
const editor = useEditor({ | ||
editorProps: { | ||
attributes: { | ||
class: 'tiptap' | ||
} | ||
}, | ||
editable: false, | ||
extensions: [ | ||
StarterKit, | ||
CodeBlockLowlight.configure({ | ||
lowlight | ||
}) | ||
], | ||
content: `<pre><code>${code}</code></pre>` | ||
}) | ||
|
||
const onCopy = () => { | ||
navigator.clipboard.writeText(code) | ||
|
||
toast.success('Copied to clipboard', { | ||
duration: 800 | ||
}) | ||
} | ||
|
||
if (!editor) return null | ||
|
||
return ( | ||
<div className='relative'> | ||
<EditorContent editor={editor} /> | ||
<Tooltip content='Copy'> | ||
<IconButton | ||
variant='ghost' | ||
size='2' | ||
color='gray' | ||
type='button' | ||
className='absolute right-3 top-7 text-gray-8 hover:text-gray-1' | ||
onClick={onCopy} | ||
> | ||
<BiCopy /> | ||
</IconButton> | ||
</Tooltip> | ||
</div> | ||
|
||
) | ||
} | ||
|
||
export default CodeBlock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters