Skip to content

Instantly share code, notes, and snippets.

@devStepsize
devStepsize / webcontents_send.js
Last active April 22, 2016 21:18
An example of sending messages from the main process to the renderer process.
// In the main process.
var window = null;
app.on('ready', function() {
window = new BrowserWindow({width: 800, height: 600});
window.loadURL('file://' + __dirname + '/index.html');
window.webContents.on('did-finish-load', function() {
window.webContents.send('ping', 'whoooooooh!');
});
});
@devStepsize
devStepsize / botkit_slack_say.js
Created April 22, 2016 21:03
Botkit say something on Slack
// From https://github.com/howdyai/botkit#botsay
bot.say(
{
text: 'my message text',
channel: 'C0H338YH4' // a valid slack channel, group, mpim, or im ID
}
);
@devStepsize
devStepsize / botkit_slack_say.js
Created April 22, 2016 21:02
Botkit say something on Slack
bot.say(
{
text: 'my message text',
channel: 'C0H338YH4' // a valid slack channel, group, mpim, or im ID
}
);
@devStepsize
devStepsize / botkit_extract_responses.js
Last active April 22, 2016 21:00
Botkit extract responses during the course of a conversation
var values = convo.extractResponses();
var value = values.key;
// alternatively, you can use
var value = convo.extractResponse('key');
@devStepsize
devStepsize / botkit_convo_flow.js
Created April 22, 2016 20:57
Botkit functions to control the flow of the conversation
// From https://github.com/howdyai/botkit#conversation-control-functions
convo.say(message)
convo.sayFirst(message) // inject a mmessage into the first spot in the queue
convo.stop() // end the convo immediately and set convo.status to stopped
convo.repeat() // repeat the last question and continue to wait for a response
convo.silentRepeat() // simply wait for another response without saying anything
convo.next() // must be called at the end of each handler
@devStepsize
devStepsize / botkit_convo_chain.js
Created April 22, 2016 20:06
Botkit conversation with multiple stages by chaining asks
// From https://github.com/howdyai/botkit#multi-stage-conversations
controller.hears(['pizzatime'], 'message_recieved', function(bot,message) {
askFlavor = function(response, convo) {
convo.ask('What flavor of pizza do you want?', function(response, convo) {
convo.say('Awesome.');
askSize(response, convo);
convo.next();
});
}
askSize = function(response, convo) {
@devStepsize
devStepsize / botkit_convo_ask_array.js
Created April 22, 2016 20:04
Botkit conversation ask with array of multiple callbacks
// From https://github.com/howdyai/botkit#using-conversationask-with-an-array-of-callbacks
controller.hears(['question me'], 'message_received', function(bot,message) {
// start a conversation to handle this response.
bot.startConversation(message,function(err,convo) {
convo.ask('Shall we proceed Say YES, NO or DONE to quit.',[
{
pattern: 'done',
callback: function(response,convo) {
@devStepsize
devStepsize / botkit_convo_ask.js
Last active April 22, 2016 20:04
Botkit conversation with ask and a single callback
// From https://github.com/howdyai/botkit#using-conversationask-with-a-callback
controller.hears(['question me'], 'message_received', function(bot,message) {
// start a conversation to handle this response.
bot.startConversation(message,function(err,convo) {
convo.ask('How are you?',function(response,convo) {
convo.say('Cool, you said: ' + response.text);
convo.next();
bot.reply(message, {
attachment: {
'type':'template',
'payload':{
'template_type':'generic',
'elements':[
{
'title':'Classic White T-Shirt',
'image_url':'http://petersapparel.parseapp.com/img/item100-thumb.png',
'subtitle':'Soft white cotton t-shirt is back in style',
var reply_with_attachments = {
'username': 'My bot' ,
'text': 'This is a pre-text',
'attachments': [
{
'fallback': 'To be useful, I need you to invite me in a channel.',
'title': 'How can I help you?',
'text': 'To be useful, I need you to invite me in a channel ',
'color': '#7CD197'
}