Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
, scan$: scanner$
}
}
const keyMarker = '?access-key='
function parseQR(url) {
const p = urlutil.parse(url)
return (p && p.host)
? { serverUrl: p.search ? url.substr(0, url.indexOf('?')) : url
, accessKey: p.search && p.search.startsWith(keyMarker) ? p.search.substr(keyMarker.length) : null }
: null
}
run(main, {
DOM: makeDOMDriver('#app')
, IPC: process.env.BUILD_TARGET === 'electron'
? require('./driver/electron-ipc')
: _ => _ => O.of() // noop driver
, storage: storageDriver
, route: makeRouteDriver(makeHashHistoryDriver())
, conf$: makeConfDriver(storageDriver)
, scan$: process.env.BUILD_TARGET === 'cordova'
? require('./driver/cordova-qrscanner')
: require('./driver/instascan')({ mirror: false, backgroundScan: false })
})
})},
{
type: Update,
name: 'not-found',
component: ({ props }) => {
t.fail(`wrong command \`${props[0]}\``)
}}
]
let main = (s: Sources) => ({
bot: $.from([
matchStream(s.bot.events('message').filter(entityIs('bot_command')), plugins, s)
.pluck('bot')
.mergeAll()
])
})
let { sources, run } = Cycle(main, { bot: basicDriver })
run()
okTake(t, sources, (message) => {
t.ok(Message.is(Message(message)), 'message satisfies typecheck')
t.ok(
/\/(help)(?:@goodmind_test_bot)?(\s+(.+))?/.test(message.reply_to_message.text),
'reply to message text should match `/help` command pattern')
t.equal(
message.text,
'Cycle Telegram v1.1.1 (https://git.io/vrs3P)',
'message text should be equal to `Cycle Telegram v1.1.1 (https://git.io/vrs3P)`')
t.end()
})
})
test('should send location with basic driver', t => {
let basicDriver = makeTelegramDriver(ACCESS_TOKEN, { skipUpdates: true })
let main = () => ({
bot: $.from([
$.of(sendLocation(
{ chat_id: GROUP_ID, latitude: 55.751244, longitude: 37.618423 },
{}))
])
})
let { sources, run } = Cycle(main, { bot: basicDriver })
run()
okTake(t, sources, (message) => {
t.ok(Message.is(Message(message)), 'message satisfies typecheck')
t.ok(message.hasOwnProperty('location'), 'message has property location')
t.end()
})
})
dbg(resps, 'spark:rpc')
dbg({ state$ }, 'spark:model')
dbg({ rpc$, vdom$, navto$, notif$, orient$, scanner$ }, 'spark:sinks')
return {
DOM: vdom$
, HTTP: rpc.toHttp(serverInfo, rpc$)
, route: navto$
, conf$: state$.map(s => s.conf)
, scan$: scanner$
, orient$
, notif$
}
}
run(main, {
DOM: makeDOMDriver('#app')
, SSE: makeSSEDriver(serverInfo)
, HTTP: makeHTTPDriver()
, route: makeRouteDriver(captureClicks(makeHashHistoryDriver()))
, conf$: makeConfDriver(storageDriver)
, orient$: orientDriver
, ...(
process.env.BUILD_TARGET == 'cordova' ? {
urihandler$: require('./driver/cordova-urihandler')
, scan$: require('./driver/cordova-qrscanner')
, notif$: require('./driver/cordova-notification')
}
: process.env.BUILD_TARGET == 'electron' ? {
import makeRouteDriver from './driver/route'
import makeSearchDriver from './driver/search'
import makeScanDriver from './driver/instascan'
import { Observable as O } from './rxjs'
import main from './app'
const apiBase = (process.env.API_URL || '/api').replace(/\/+$/, '')
, webBase = process.env.BASE_HREF || '/'
, initTitle = process.browser ? document.title : process.env.SITE_TITLE
const titleDriver = title$ => O.from(title$)
.subscribe(title => document.title = title ? `${title} · ${initTitle}` : initTitle)
run(main, {
DOM: makeDOMDriver('#explorer')
, HTTP: makeHTTPDriver()
, route: makeRouteDriver(captureClicks(makeHistoryDriver({ basename: webBase })))
, storage: storageDriver
, search: makeSearchDriver(apiBase)
, title: titleDriver
, scanner: makeScanDriver()
})
seenLoading = true
clearTimeout(timeout)
timeout = setTimeout(_ => done({ errorCode: 504 }), LOAD_TIMEOUT)
}
}
else if (seenLoading) done()
}
const historyDriver = goto$ => {
O.from(goto$).subscribe(loc =>
done({ redirect: loc.pathname + (loc.search || '') })
)
return O.of({ pathname, search: '?'+args, body })
}
const dispose = run(main, {
DOM: makeHTMLDriver(htmlUpdate, { modules: ModulesForHTML })
, HTTP: makeHTTPDriver()
, route: makeRouteDriver(historyDriver)
, storage: _ => ({ local: { getItem: key => O.of(locals[key]) } })
, scanner: _ => O.empty()
, search: makeSearchDriver(apiBase)
, state: state$ => O.from(state$).subscribe(stateUpdate)
})
}