Skip to content

Commit 2f77504

Browse files
committed
feat: Improve Calendly integration and meeting booking flow
1 parent d06b9be commit 2f77504

File tree

3 files changed

+51
-20
lines changed

3 files changed

+51
-20
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
'use client'
2+
3+
import React, { useEffect, useRef } from 'react';
4+
import Script from 'next/script';
5+
6+
interface CalendlyWidgetProps {
7+
url: string;
8+
}
9+
10+
export const CalendlyWidget: React.FC<CalendlyWidgetProps> = ({ url }) => {
11+
const containerRef = useRef<HTMLDivElement>(null);
12+
13+
useEffect(() => {
14+
if (url && window.Calendly && containerRef.current) {
15+
window.Calendly.initInlineWidget({
16+
url,
17+
parentElement: containerRef.current,
18+
prefill: {},
19+
utm: {}
20+
});
21+
}
22+
}, [url]);
23+
24+
return (
25+
<>
26+
<Script
27+
src="https://assets.calendly.com/assets/external/widget.js"
28+
strategy="lazyOnload"
29+
/>
30+
<div
31+
ref={containerRef}
32+
className="calendly-inline-widget"
33+
style={{
34+
minWidth: '320px',
35+
height: '700px'
36+
}}
37+
/>
38+
</>
39+
);
40+
};
41+
42+
declare global {
43+
interface Window {
44+
Calendly?: any;
45+
}
46+
}

src/app/(chat)/ask-anything/[chatId]/_components/ShowMessage.tsx

+4-19
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,31 @@
1-
import React, { useEffect } from 'react'
1+
import React from 'react'
22
import { useQuery } from '@tanstack/react-query'
33
import rehypeKatex from 'rehype-katex'
44
import remarkGfm from 'remark-gfm'
55
import remarkMath from 'remark-math'
66

77
import { getConfiguration } from '@/apis/admin/configuration'
88
import { MessageMarkdownMemoized } from './MessageMarkdownMemoized'
9+
import {CalendlyWidget} from '@/app/(chat)/ask-anything/[chatId]/_components/CalendlyWidget'
910

1011
interface ShowMessageProps {
1112
message: string
1213
components: object
1314
}
1415

1516
const ShowMessage: React.FC<ShowMessageProps> = ({ message, components }) => {
16-
useEffect(() => {
17-
if (message === 'BOOK_MEETING') {
18-
const script = document.createElement('script')
19-
script.src = 'https://assets.calendly.com/assets/external/widget.js'
20-
script.async = true
21-
document.body.appendChild(script)
22-
23-
return () => {
24-
document.body.removeChild(script)
25-
}
26-
}
27-
}, [message])
28-
2917
// Fetch Calendly URL from DB
3018
const { data: calendlyUrlData } = useQuery({
3119
queryKey: ['calendlyUrl'],
3220
queryFn: getConfiguration,
3321
})
3422

35-
const calendlyUrl = calendlyUrlData?.credentials[0].calendlyMeetingLink
23+
const calendlyUrl = calendlyUrlData?.credentials[0]?.calendlyMeetingLink || process.env.NEXT_PUBLIC_CALENDLY || ''
3624

3725
if (message === 'BOOK_MEETING') {
3826
return (
3927
<div className='mx-auto w-full min-w-full max-w-[1000px] overflow-hidden rounded-xl'>
40-
<div
41-
className='calendly-inline-widget relative h-[500px] w-[285px] pb-[100%] sm:w-[300px] sm:pb-[75%] md:w-[420px]'
42-
data-url={calendlyUrl || process.env.NEXT_PUBLIC_CALENDLY}
43-
/>
28+
<CalendlyWidget url={calendlyUrl} />
4429
</div>
4530
)
4631
} else {

src/services/chat/conversation.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const AVAILABLE_TOOLS: OpenAI.Chat.ChatCompletionTool[] = [
2020
type: 'function',
2121
function: {
2222
name: 'book_meeting_call_appointment',
23-
description: 'Books calls, meetings, or appointments with RipeSeed',
23+
description: 'Connect with RipeSeed to schedule a meeting or appointment. This will display a Calendly widget for easy booking.',
2424
parameters: {
2525
type: 'object',
2626
properties: {},

0 commit comments

Comments
 (0)