Created
May 11, 2019 06:26
-
-
Save carsonfarmer/d9c7506fc83c7330404f2faf07fd213c to your computer and use it in GitHub Desktop.
Adding some Textile functionality
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/index.js b/index.js | |
index 4cf1473..598b1d1 100644 | |
--- a/index.js | |
+++ b/index.js | |
@@ -1,6 +1,7 @@ | |
#!/usr/bin/env node | |
const cli = require('cac')('txtl') | |
+const textile = require('@textile/js-http-client').default | |
var readline = require('readline') | |
const { log } = console | |
@@ -8,7 +9,6 @@ const { log } = console | |
// Create 'default' chat command | |
cli.command('', 'Starts an interactive chat session in a thread.') | |
.action((opts) => { | |
- log('do something') | |
// Specify our readline interface | |
const rl = readline.createInterface({ | |
input: process.stdin, | |
@@ -18,10 +18,22 @@ cli.command('', 'Starts an interactive chat session in a thread.') | |
// Run callback for each input on stdin | |
rl.on('line', (line) => { | |
if (line !== '') { | |
- log(line) | |
- rl.prompt() | |
+ textile.messages.add(opts.thread, line) | |
+ .then(() => { rl.prompt() }) | |
} | |
}) | |
+ // Get our 'local' profile info... | |
+ textile.profile.get() | |
+ .then((peer) => { | |
+ // ... and then create a custom prompt | |
+ rl.setPrompt(peer.name || peer.address.slice(7) + '\t') | |
+ rl.prompt() // Display prompt to get started | |
+ // Only subscribe to text events on the specified thread | |
+ textile.subscribe.stream(['TEXT'], opts.thread) | |
+ .then((stream) => { | |
+ log('do something') | |
+ }) | |
+ }) | |
}) | |
.option('--thread [thread]', 'Thread ID. Omit to use the \'default\' thread.', { | |
default: 'default', |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment