Todd Halfpenny
Images: https://dev.slack.com/
{
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "This is a header block",
"emoji": true
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "New Paid Time Off request from \n\n"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Pick a date for the deadline."
},
"accessory": {
"type": "datepicker",
"initial_date": "1990-04-28",
"placeholder": {
"type": "plain_text",
"text": "Select a date",
"emoji": true
},
"action_id": "datepicker-action"
}
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Click Me",
"emoji": true
},
"value": "click_me_123",
"action_id": "actionId-0"
}
]
}
]
}
const whoamiCallback = async ({ shortcut, ack, client }) => {
await client.views.open({
trigger_id: shortcut.trigger_id,
view: whoAmIResponse(
conn.instanceUrl,
currentuser.username)
});
};
module.exports.register = (app) => {
app.shortcut('who_am_i', whoamiCallback);
};
Image: https://developer.salesforce.com/blogs/
.
├── apps
│ └── salesforce-slack-app
├── force-app
│ └── main
├── package.json
├── README.md
├── scripts
│ ├── deploy.js
│ └── templates
└── sfdx-project.json
module.exports.register = (app) => {
app.event('app_home_opened', appHomeOpenedCallback);
};
const queryListingSummaries = async (connection) => {
// Query for store listing summary
const result = await connection.query(
`SELECT OS__c, Total_Downloads__c, ...
FROM Listing_Summary__c
ORDER BY CreatedDate DESC LIMIT 10`
);
return result;
}
const { HomeTab, Blocks, Elements, Md, Actions }
= require('slack-block-builder');
const dashboardScreen = (listingSummaries) => {
const homeTab = HomeTab().blocks(
Blocks.Header({ text: `App Store Listing Summaries` })
);
const listingArray = listingSummaries.records.map(
osEmoji(listing, requestIndex) => {
let listingText = `${Md.bold(listing.OS__c)}\n`;
...
return listingText;
}
homeTab.blocks(Blocks.Section().fields(listingArray));
return homeTab.buildToJSON();
}
public class EventDispatcherAppHomeOpened extends
Slack.EventDispatcher {
...
public class Handler implements Slack.RunnableHandler {
public void run() {
Slack.ViewReference viewReference =
Slack.View.app_home.get();
...
Slack.ViewsPublishResponse response =
botClient.viewsPublish(req);
}
}
...
}
public with sharing class DataProviderReview {
public static List<Review__c> getReviews() {
List<Review__c> reviews =
[SELECT Id, Name, Date__c, ...
FROM Review__c
ORDER BY Date__c DESC LIMIT 5];
return reviews;
}
}
dataproviders:
review:
definition: "apex__DataProviderReview.getReviews"
components:
- definition: home
components:
- definition: header
properties:
text: "Recent reviews"
- definition: iteration
properties:
foreach: "{!review}"
foritem: "review"
components:
- definition: section
properties:
text:
text: "{!IF(review.OS__c == 'iOS',\
':apple:', \
':robot_face:')} \n
*Review:* {!review.Content__c}"
type: mrkdwn
Todd Halfpenny