Advertisement
Guest User

paysapp_keybase

a guest
Dec 9th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // PAYSAPP for KEYBASE
  2.  
  3. const kBot     = require('keybase-bot')
  4. const bot      = new kBot()
  5. const username = process.env.BOTNAME;
  6. const paperkey = process.env.BOTKEY;
  7.  
  8. bot.init(username, paperkey, {verbose: true})
  9.     .then(() => {
  10.         console.log('Paysapp bot initialized')
  11.         const channel   = {name: bot.myInfo().username, public: true, topicType: 'chat'}
  12.        
  13.         const onMessage = message => {
  14.             console.log('> Message', message) // Deaf bot, never seeing any message
  15.             if (message.content.type === 'text') {
  16.                 const body  = message.content.text.body;
  17.                 const words = text.trim().split(/\s+/);
  18.                 if(words.length<1) { return }
  19.                 const action = words[0]
  20.                 console.log('Action',action)
  21.                 if (action == 'hello') {
  22.                     reply = { body: 'Welcome to Paysapp\nMore actions coming soon...' }
  23.                     bot.chat.send(message.channel, reply)
  24.                 }
  25.             } else {
  26.                 reply = { body: 'Invalid action' }
  27.                 bot.chat.send(message.channel, reply)
  28.                 console.log('Invalid message')
  29.             }
  30.         }
  31.        
  32.         const onError = ex => console.error(ex)
  33.      
  34.       bot.chat.watchChannelForNewMessages(channel, onMessage, onError)
  35.  
  36. })
  37. .catch(error => {
  38.     //console.error("error", error.message)
  39.     console.error(error)
  40.     bot.deinit()
  41. })
  42.  
  43. console.log('Paysapp bot running...');
  44.  
  45.  
  46. // END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement