🏷 (pkg/decidim) SDK types for learn step
This MR is a proposal for packages/decidim
types.
What I have done:
- create generic types for buttons and texts
- export types for response (if we are in conversations, or in a section like
learn
).
Here an example on how it will be used, inspired by the snippet we've done.
async () => {
const convId = "chatbotId:userId:whatever:you:want"
const conversation = await decidim.conversation(convId)
const introductionText = await conversation.introductionText();
const introductionTextExample: typeof introductionText = {
text: [
"Welcome in the assembly Economy",
"This assembly works in steps: ",
"* 12/01: information",
"* **15/02: proposal**",
"* 17/03: priorisation",
"* 05/04: results and decisions",
]
}
const menu = await conversation.menu()
const menuExample: typeof menu = {
text: [
"You can now read informations about",
"the assembly"
],
buttons: [
{
section: SectionType.LEARN,
params: {
component_id: "1",
component_manifest: "blogs",
space_id: "3",
space_manifest: "assemblies"
},
label: "Read __Pemba Economical Overview__"
},
{
section: SectionType.VOTE,
params: {
component_id: "4",
component_manifest: "proposals",
space_id: "3",
space_manifest: "assemblies"
},
label: "Propose"
},
]
}
// Start learning.
const textArticle = await conversation.learn.readNext({
component_id: "1",
component_manifest: "blogs",
space_id: "3",
space_manifest: "assemblies"
});
const textArticleExample: typeof textArticle = {
text: [
"Line 1",
"Line 2"
],
buttons: [
{
label: "Read More",
params: {
component_id: "1",
component_manifest: "blogs",
space_id: "3",
space_manifest: "assemblies"
},
state: LearnState.READ_MORE
}
]
}
}