Share a screenshot of your completed Confluence Hello World tutorial to earn a Badge!
Nice work!
nice work @ArnoutCator
Nice work @SeanSweeney
Nice job @HruduShibu
I did it too ^^ with slight modifications
Note: here in 4th point there is ‘service desk’ reference instead of Confluence: https://developer.atlassian.com/platform/forge/call-a-confluence-api/#make-an-api-call
my screenshot -
However while exporting I am not able to see the number of comments. It gives me as undefined. Did I missing something here ?
Hi modzelewskil,
In my code, the PDF export is not working properly, could you please share the code that works?
modules:
macro:
- key: hello-world-app-wiki-hello-world-macro
resource: main
render: native
resolver:
function: resolver
title: Forge app for Rag
description: Inserts hello world!
adfExport:
function: export-key
function:
- key: resolver
handler: index.handler
- key: export-key
handler: macroExport.exportFunction
resources:
- key: main
path: src/frontend/index.jsx
app:
runtime:
name: nodejs20.x
id: ari:cloud:ecosystem::app/7789f1d5-33bb-49a9-a2f0-095be1ba46a1
permissions:
scopes:
- read:comment:confluence
import api, { route } from '@forge/api';
import { doc, p } from '@atlaskit/adf-utils/builders';
const fetchComments = async (pageId) => {
const res = await api
.asApp()
.requestConfluence(route`/wiki/api/v2/pages/${pageId}/footer-comments`);
const data = await res.json();
return data.results;
};
export const exportFunction = async (payload) => {
const pageId = payload.context.contentId;
const comments = await fetchComments(pageId);
return doc(
p(`Number of comments on this page: ${comments.length}`),
p(`Hello world! This is an export of type ${payload.exportType}.`)
);
}
import React, { useEffect, useState } from 'react';
import ForgeReconciler, { Text, useProductContext } from '@forge/react';
import { invoke, requestConfluence } from '@forge/bridge';
const fetchCommentsForPage = async (pageId) => {
const res = await requestConfluence(`/wiki/api/v2/pages/${pageId}/footer-comments`);
const data = await res.json();
return data.results;
};
const App = () => {
const context = useProductContext();
// const [data, setData] = useState(null);
// add these code to keep track of footer comments
const [comments, setComments] = React.useState();
console.log(`Number of comments on this page: ${comments?.length}`);
// useEffect(() => {
// invoke('getText', { example: 'my-invoke-variable' }).then(setData);
// }, []);
React.useEffect(() => {
if (context) {
// extract page ID from the context
const pageId = context.extension.content.id;
fetchCommentsForPage(pageId).then(setComments);
}
}, [context]);
return (
<>
<Text>
Number of comments on this page: {comments?.length}
</Text>
<Text>Hello world!</Text>
{/* <Text>{data ? data : 'Loading...'}</Text> */}
</>
);
};
ForgeReconciler.render(
<React.StrictMode>
<App />
</React.StrictMode>
);
Hi mpaisley,
In my code, the PDF export did not work properly, could you share the full code that worked?
- manifest.yml
- index.js
- macroExport.js
Hi @Rag
It sounds like you’re having difficult with a PDF export, which is not covered in this tutorial.
I’d recommend creating a new topic over at Forge Platform and Tools - The Atlassian Developer Community.
Cheers!
Mel