Skip to content

Instantly share code, notes, and snippets.

@carsonfarmer
Created May 11, 2019 06:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carsonfarmer/d9c7506fc83c7330404f2faf07fd213c to your computer and use it in GitHub Desktop.
Save carsonfarmer/d9c7506fc83c7330404f2faf07fd213c to your computer and use it in GitHub Desktop.
Adding some Textile functionality
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