-
Notifications
You must be signed in to change notification settings - Fork 8.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Zoho Calendar #10429
Merged
Merged
feat: Zoho Calendar #10429
Changes from all commits
Commits
Show all changes
54 commits
Select commit
Hold shift + click to select a range
68ab3bf
feat: add zoho calendar
murtajaziad 3d7a699
remove log.debug
murtajaziad 8a51e76
Merge branch 'main' into app/zohocalendar
murtajaziad c64440e
fix types
murtajaziad 3d8c819
lint
murtajaziad 9ee3b12
fix types and lint
murtajaziad 6b861fd
lint
murtajaziad b046b4e
Apply suggestions from code review
hariombalhara e6c3772
Make changes to comply with new app structure - followed by app-store…
hariombalhara 10bf10d
Add dead import
hariombalhara d56a491
Merge remote-tracking branch 'origin/main' into app/zohocalendar
hariombalhara a91e12f
More cleanup
hariombalhara 2cfc402
Use slug as dirName if not explicilty set
hariombalhara 62c38e9
Added instructions for obtaining Zoho Calendar Client ID and Secret
murtajaziad 0e65ec8
Merge remote-tracking branch 'origin/main' into app/zohocalendar
hariombalhara 86c235f
Reuse code
hariombalhara 249b54c
Fix TS error
hariombalhara 29e7384
Merge remote-tracking branch 'origin/main' into app/zohocalendar
hariombalhara 37518ee
fix missing title and missing uemail
murtajaziad 5935818
Merge branch 'main' into app/zohocalendar
alannnc 735d9bf
Fixing app seed, event start end time on zoho app missmatch and fetch…
alannnc 436020e
Merge branch 'main' into app/zohocalendar
alannnc 0451429
Merge branch 'main' into app/zohocalendar
alannnc 0788823
Merge branch 'main' into app/zohocalendar
alannnc 6ce4754
Adjust CalendarService to match code style
alannnc 1cb5334
Merge branch 'main' into app/zohocalendar
joeauyeung 2d03b43
Callback use app keys schema
joeauyeung 86e00c6
Merge branch 'main' into app/zohocalendar
joeauyeung 387b106
add required etag to edit & delete
murtajaziad e78349d
Merge branch 'calcom:app/zohocalendar' into app/zohocalendar
murtajaziad f0fa4c5
Merge branch 'main' into app/zohocalendar
joeauyeung 72df29c
Merge branch 'main' into app/zohocalendar
joeauyeung 76b8022
Merge branch 'main' into app/zohocalendar
joeauyeung fd932f2
use utc plugin for zohocalendar busyData
murtajaziad a508476
Merge branch 'main' into app/zohocalendar
joeauyeung 72bad32
get zohocalendar availability for more than 31days
murtajaziad 757e82f
Merge branch 'main' into app/zohocalendar
joeauyeung 6c571e1
Merge branch 'main' into app/zohocalendar
joeauyeung 39589eb
Merge branch 'main' into app/zohocalendar
PeerRich 6d1eed5
Merge branch 'main' into app/zohocalendar
PeerRich 688a36a
Merge branch 'main' into app/zohocalendar
PeerRich 18648d3
fix destination calendar id getting from event
murtajaziad 47a6eab
Merge branch 'main' into app/zohocalendar
aar2dee2 f817f2c
Merge branch 'main' into app/zohocalendar
aar2dee2 155ac84
update description, use separate env vars
aar2dee2 e590480
update readme
aar2dee2 442f403
Update turbo.json
aar2dee2 42a69ca
Update .env.appStore.example
aar2dee2 f500196
revert seed app-store
aar2dee2 08d3036
Merge branch 'main' into app/zohocalendar
aar2dee2 f527ae9
use createOAuthAppCredential
murtajaziad f539632
images change & add
murtajaziad 5167226
extract oauth base url to variable
murtajaziad d134691
Update packages/app-store/zohocalendar/api/callback.ts
hariombalhara File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -504,6 +504,9 @@ For example, `Cal.com ([email protected])`. | |
9. Click the "Save"/ "UPDATE" button at the bottom footer. | ||
10. You're good to go. Now you can easily add your ZohoCRM integration in the Cal.com settings. | ||
|
||
### Obtaining Zoho Calendar Client ID and Secret | ||
|
||
[Follow these steps](./packages/app-store/zohocalendar/) | ||
### Obtaining Zoho Bigin Client ID and Secret | ||
|
||
[Follow these steps](./packages/app-store/zoho-bigin/) | ||
|
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
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
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,9 @@ | ||
--- | ||
items: | ||
- ZCal1.jpg | ||
- ZCal2.jpg | ||
- ZCal3.jpg | ||
- ZCal4.jpg | ||
--- | ||
|
||
Zoho Calendar is an online business calendar that makes scheduling easy for you. Use this app to sync your Cal bookings with your Zoho Calendar. |
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,16 @@ | ||
## Zoho Calendar | ||
|
||
### Obtaining Zoho Calendar Client ID and Secret | ||
|
||
1. Open [Zoho API Console](https://api-console.zoho.com/) and sign into your account, or create a new one. | ||
2. Create a "Server-based Applications", set the Redirect URL for OAuth `<Cal.com URL>/api/integrations/zohocalendar/callback` replacing Cal.com URL with the URI at which your application runs. | ||
4. Fill in any information you want in the "Client Details" tab | ||
5. Go to tab "Client Secret" tab. | ||
6. Now copy the Client ID and Client Secret into your app keys in the Cal.com admin panel (`<Cal.com>/settings/admin/apps`). | ||
7. Back in Zoho API Console, | ||
8. In the "Settings" section check the "Multi-DC" option if you wish to use the same OAuth credentials for all data centers. | ||
9. Click the "Save"/ "UPDATE" button at the bottom footer. | ||
10. You're good to go. Now you can easily add your Zoho Calendar integration in the Cal.com settings at `/settings/my-account/calendars`. | ||
11. You can access your Zoho calendar at [https://calendar.zoho.com/](https://calendar.zoho.com/) | ||
|
||
NOTE: If you use multiple calendars with Cal, make sure you enable the toggle to prevent double-bookings across calendar. This is in `/settings/my-account/calendars`. |
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,42 @@ | ||
import type { NextApiRequest, NextApiResponse } from "next"; | ||
import { stringify } from "querystring"; | ||
|
||
import { WEBAPP_URL } from "@calcom/lib/constants"; | ||
import { defaultHandler, defaultResponder } from "@calcom/lib/server"; | ||
|
||
import { encodeOAuthState } from "../../_utils/encodeOAuthState"; | ||
import getAppKeysFromSlug from "../../_utils/getAppKeysFromSlug"; | ||
import config from "../config.json"; | ||
import { appKeysSchema as zohoKeysSchema } from "../zod"; | ||
|
||
const OAUTH_BASE_URL = "https://accounts.zoho.com/oauth/v2"; | ||
|
||
async function getHandler(req: NextApiRequest, res: NextApiResponse) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @hariombalhara There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, that would be a good idea. We can create a task for it. |
||
const appKeys = await getAppKeysFromSlug(config.slug); | ||
const { client_id } = zohoKeysSchema.parse(appKeys); | ||
|
||
const state = encodeOAuthState(req); | ||
|
||
const params = { | ||
client_id, | ||
response_type: "code", | ||
redirect_uri: WEBAPP_URL + "/api/integrations/zohocalendar/callback", | ||
scope: [ | ||
"ZohoCalendar.calendar.ALL", | ||
"ZohoCalendar.event.ALL", | ||
"ZohoCalendar.freebusy.READ", | ||
"AaaServer.profile.READ", | ||
], | ||
access_type: "offline", | ||
state, | ||
prompt: "consent", | ||
}; | ||
|
||
const query = stringify(params); | ||
|
||
res.status(200).json({ url: `${OAUTH_BASE_URL}/auth?${query}` }); | ||
} | ||
|
||
export default defaultHandler({ | ||
GET: Promise.resolve({ default: defaultResponder(getHandler) }), | ||
}); |
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,76 @@ | ||
import type { NextApiRequest, NextApiResponse } from "next"; | ||
import { stringify } from "querystring"; | ||
|
||
import { WEBAPP_URL } from "@calcom/lib/constants"; | ||
import { getSafeRedirectUrl } from "@calcom/lib/getSafeRedirectUrl"; | ||
import logger from "@calcom/lib/logger"; | ||
import { defaultHandler, defaultResponder } from "@calcom/lib/server"; | ||
|
||
import createOAuthAppCredential from "../../_utils/createOAuthAppCredential"; | ||
import { decodeOAuthState } from "../../_utils/decodeOAuthState"; | ||
import getAppKeysFromSlug from "../../_utils/getAppKeysFromSlug"; | ||
import getInstalledAppPath from "../../_utils/getInstalledAppPath"; | ||
import config from "../config.json"; | ||
import type { ZohoAuthCredentials } from "../types/ZohoCalendar"; | ||
import { appKeysSchema as zohoKeysSchema } from "../zod"; | ||
|
||
const log = logger.getChildLogger({ prefix: [`[[zohocalendar/api/callback]`] }); | ||
|
||
const OAUTH_BASE_URL = "https://accounts.zoho.com/oauth/v2"; | ||
|
||
async function getHandler(req: NextApiRequest, res: NextApiResponse) { | ||
const { code } = req.query; | ||
const state = decodeOAuthState(req); | ||
|
||
if (code && typeof code !== "string") { | ||
res.status(400).json({ message: "`code` must be a string" }); | ||
return; | ||
} | ||
|
||
if (!req.session?.user?.id) { | ||
return res.status(401).json({ message: "You must be logged in to do this" }); | ||
} | ||
|
||
const appKeys = await getAppKeysFromSlug(config.slug); | ||
const { client_id, client_secret } = zohoKeysSchema.parse(appKeys); | ||
|
||
const params = { | ||
client_id, | ||
grant_type: "authorization_code", | ||
client_secret, | ||
redirect_uri: `${WEBAPP_URL}/api/integrations/${config.slug}/callback`, | ||
code, | ||
}; | ||
|
||
const query = stringify(params); | ||
|
||
const response = await fetch(`${OAUTH_BASE_URL}/token?${query}`, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json; charset=utf-8", | ||
}, | ||
}); | ||
|
||
const responseBody = await response.json(); | ||
|
||
if (!response.ok || responseBody.error) { | ||
log.error("get access_token failed", responseBody); | ||
return res.redirect("/apps/installed?error=" + JSON.stringify(responseBody)); | ||
} | ||
|
||
const key: ZohoAuthCredentials = { | ||
access_token: responseBody.access_token, | ||
refresh_token: responseBody.refresh_token, | ||
expires_in: Math.round(+new Date() / 1000 + responseBody.expires_in), | ||
}; | ||
|
||
await createOAuthAppCredential({ appId: config.slug, type: config.type }, key, req); | ||
|
||
res.redirect( | ||
getSafeRedirectUrl(state?.returnTo) ?? getInstalledAppPath({ variant: config.variant, slug: config.slug }) | ||
); | ||
} | ||
|
||
export default defaultHandler({ | ||
GET: Promise.resolve({ default: defaultResponder(getHandler) }), | ||
}); |
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,2 @@ | ||
export { default as add } from "./add"; | ||
export { default as callback } from "./callback"; |
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,16 @@ | ||
{ | ||
"name": "Zoho Calendar", | ||
"description": "Zoho Calendar is an online business calendar that makes scheduling easy for you. You can use it to stay on top of your schedule and also share calendars with your team to keep everyone on the same page.", | ||
"slug": "zohocalendar", | ||
"type": "zoho_calendar", | ||
"title": "Zoho Calendar", | ||
"variant": "calendar", | ||
"category": "calendar", | ||
"categories": [ | ||
"calendar" | ||
], | ||
"logo": "icon.svg", | ||
"publisher": "Cal.com", | ||
"url": "https://cal.com/", | ||
"email": "[email protected]" | ||
} |
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,2 @@ | ||
export * as api from "./api"; | ||
export * as lib from "./lib"; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add more screenshots. We can show installation steps, if needed.
See other calendar apps for reference
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done