-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
QRcode block #1142
QRcode block #1142
Conversation
@dkashikar is attempting to deploy a commit to the Typebot Team on Vercel. A member of the Team first needs to authorize it. |
WalkthroughThe Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
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.
Review Status
Actionable comments generated: 1
Configuration used: CodeRabbit UI
Files ignored due to filter (4)
- packages/forge/blocks/qrcode/package.json
- packages/forge/blocks/qrcode/tsconfig.json
- packages/forge/schemas/package.json
- pnpm-lock.yaml
Files selected for processing (5)
- packages/forge/blocks/qrcode/actions/displayQr.ts (1 hunks)
- packages/forge/blocks/qrcode/index.ts (1 hunks)
- packages/forge/blocks/qrcode/logo.tsx (1 hunks)
- packages/forge/repository/index.ts (1 hunks)
- packages/forge/schemas/index.ts (2 hunks)
Files skipped from review due to trivial changes (2)
- packages/forge/blocks/qrcode/logo.tsx
- packages/forge/repository/index.ts
Additional comments: 2
packages/forge/blocks/qrcode/index.ts (1)
- 1-11: The block definition for
qrcode
looks correct and follows the expected structure for defining a new block within the@typebot.io/forge
package. The use ofcreateBlock
with the appropriate properties such asid
,name
,tags
,LightLogo
, andactions
is consistent with the package's design patterns.packages/forge/schemas/index.ts (1)
- 1-5: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [2-20]
The import of
qrcode
from@typebot.io/qrcode-block
and its addition to theforgedBlocks
array are correctly implemented. This change will ensure that theqrcode
block is registered and available for use within theforge
package.
export const displayQr = createAction({ | ||
name: 'Display Qr', | ||
options: option.object({ | ||
qrvalue: option.string.layout({ | ||
label: 'Qr Code', | ||
helperText: 'QR code to show' | ||
}), | ||
qrlink: option.string.layout({ | ||
label: 'Qr link', | ||
helperText: 'Link to goto on tapping QR code' | ||
}), | ||
}), | ||
run: { | ||
web: { | ||
displayEmbedBubble: { | ||
parseInitFunction: ({ options }) => { | ||
if (!options.qrvalue) throw new Error('Missing Qr Code') | ||
var qr = qrcode(8, 'L'); | ||
qr.addData(options.qrvalue); | ||
qr.make(); | ||
const qrvalue = qr.createDataURL(); | ||
return { | ||
args: { | ||
qrvalue: qrvalue, | ||
qrlink: options.qrlink ?? null | ||
}, | ||
content: `let qr = document.createElement("img");qr.src = qrvalue;qr.classList.add('w-full');; let link = document.createElement("a"); link.href = qrlink; link.target = '_blank'; link.appendChild(qr); typebotElement.appendChild(qrlink ? link : qr);`, | ||
} | ||
}, | ||
}, | ||
} | ||
}, | ||
}) |
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.
The displayQr
action is well-defined with clear options for qrvalue
and qrlink
. The error handling for a missing qrvalue
is appropriate. However, the run
method's parseInitFunction
contains a script that is directly manipulating the DOM, which could be improved for maintainability and security reasons. It's recommended to abstract this logic into a separate, sanitized function or use a framework-specific way to manipulate the DOM if available.
- content: `let qr = document.createElement("img");qr.src = qrvalue;qr.classList.add('w-full');; let link = document.createElement("a"); link.href = qrlink; link.target = '_blank'; link.appendChild(qr); typebotElement.appendChild(qrlink ? link : qr);`,
+ // It's recommended to abstract this logic into a separate function or use a framework-specific way to manipulate the DOM.
Committable suggestion
❗ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
export const displayQr = createAction({ | |
name: 'Display Qr', | |
options: option.object({ | |
qrvalue: option.string.layout({ | |
label: 'Qr Code', | |
helperText: 'QR code to show' | |
}), | |
qrlink: option.string.layout({ | |
label: 'Qr link', | |
helperText: 'Link to goto on tapping QR code' | |
}), | |
}), | |
run: { | |
web: { | |
displayEmbedBubble: { | |
parseInitFunction: ({ options }) => { | |
if (!options.qrvalue) throw new Error('Missing Qr Code') | |
var qr = qrcode(8, 'L'); | |
qr.addData(options.qrvalue); | |
qr.make(); | |
const qrvalue = qr.createDataURL(); | |
return { | |
args: { | |
qrvalue: qrvalue, | |
qrlink: options.qrlink ?? null | |
}, | |
content: `let qr = document.createElement("img");qr.src = qrvalue;qr.classList.add('w-full');; let link = document.createElement("a"); link.href = qrlink; link.target = '_blank'; link.appendChild(qr); typebotElement.appendChild(qrlink ? link : qr);`, | |
} | |
}, | |
}, | |
} | |
}, | |
}) | |
export const displayQr = createAction({ | |
name: 'Display Qr', | |
options: option.object({ | |
qrvalue: option.string.layout({ | |
label: 'Qr Code', | |
helperText: 'QR code to show' | |
}), | |
qrlink: option.string.layout({ | |
label: 'Qr link', | |
helperText: 'Link to goto on tapping QR code' | |
}), | |
}), | |
run: { | |
web: { | |
displayEmbedBubble: { | |
parseInitFunction: ({ options }) => { | |
if (!options.qrvalue) throw new Error('Missing Qr Code') | |
var qr = qrcode(8, 'L'); | |
qr.addData(options.qrvalue); | |
qr.make(); | |
const qrvalue = qr.createDataURL(); | |
return { | |
args: { | |
qrvalue: qrvalue, | |
qrlink: options.qrlink ?? null | |
}, | |
// It's recommended to abstract this logic into a separate function or use a framework-specific way to manipulate the DOM. | |
} | |
}, | |
}, | |
} | |
}, | |
}) |
Hey! That's a nice idea 👍 The |
I also think it would be better to generate the QR Code as an image URL that can be then used in an Image bubble. So that we can use this block on other environment like whatsapp |
Thanks.
i can rewrite using this package
super. have done this. |
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.
Review Status
Actionable comments generated: 1
Configuration used: CodeRabbit UI
Files ignored due to filter (2)
- packages/forge/blocks/qrcode/package.json
- pnpm-lock.yaml
Files selected for processing (3)
- packages/forge/blocks/qrcode/actions/convertQr.ts (1 hunks)
- packages/forge/blocks/qrcode/index.ts (1 hunks)
- packages/forge/blocks/qrcode/logo.tsx (1 hunks)
Files skipped from review due to trivial changes (1)
- packages/forge/blocks/qrcode/logo.tsx
Additional comments: 1
packages/forge/blocks/qrcode/index.ts (1)
- 1-11: The implementation of the
qrcode
block appears to be correct and follows the expected pattern for block creation within the@typebot.io/forge
framework. The use ofcreateBlock
with the appropriate properties and the inclusion ofQrcodeLogo
andconvertQr
suggest that the block is well-integrated with the necessary functionality for QR code generation and display.
Made the error messages more user-friendly Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- packages/forge/blocks/qrcode/actions/convertQr.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- packages/forge/blocks/qrcode/actions/convertQr.ts
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (7)
- packages/forge/blocks/qrcode/actions/generateQrCodeImage.ts (1 hunks)
- packages/forge/blocks/qrcode/index.ts (1 hunks)
- packages/forge/blocks/qrcode/logo.tsx (1 hunks)
- packages/forge/core/index.ts (2 hunks)
- packages/forge/core/types.ts (2 hunks)
- packages/forge/repository/index.ts (1 hunks)
- packages/forge/schemas/index.ts (2 hunks)
Files skipped from review due to trivial changes (1)
- packages/forge/repository/index.ts
Files skipped from review as they are similar to previous changes (2)
- packages/forge/blocks/qrcode/index.ts
- packages/forge/blocks/qrcode/logo.tsx
Additional comments: 8
packages/forge/schemas/index.ts (2)
2-2: The import of
qrCode
is correctly added and follows the existing pattern of imports.20-20: The addition of
qrCode
to theforgedBlocks
array aligns with the PR objectives to integrate QR code functionality into theforge
package.packages/forge/blocks/qrcode/actions/generateQrCodeImage.ts (2)
1-4: The import statements are correctly added and follow the existing pattern of imports.
6-40: The
generateQrCode
action is well-defined with clear options and error handling, aligning with the PR objectives to generate and display QR codes.packages/forge/core/types.ts (2)
3-3: The import of
ZodRawShape
is correctly added and is necessary for the modifications made to theActionDefinition
type.32-33: The modifications to the
ActionDefinition
type, specifying default generic types forBaseOptions
andOptions
, are appropriate and align with the PR objectives.packages/forge/core/index.ts (2)
1-1: The import of
ZodRawShape
is correctly added and is necessary for the modifications made to thecreateAction
function.22-23: The modifications to the
createAction
function's type declarations, specifically for theBaseOptions
andO
parameters, are appropriate and align with the PR objectives.
@dkashikar I've renamed things to proper camel case when necessary and I also properly set up the image generation so that it is uploaded to S3 instance. Otherwise, a data URI can't be used in WhatsApp. Thanks again for your work! |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- packages/forge/blocks/qrcode/actions/generateQrCodeImage.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- packages/forge/blocks/qrcode/actions/generateQrCodeImage.ts
Thanks again for your work @dkashikar. 🙏 Let me know if there's anything we can improve in terms of DX. |
Thank you @baptisteArno |
That would be nice, we need a system to encrypt the value then because I don't want to make the user think his value is private when it's not in reality. I'll work on that ASAP (#627) |
This block is able to :
Summary by CodeRabbit