/** * Attempts a simple upgrade, eventually calling npm install -g npm * * @param {string} version - Version that should be installed * @private */ async upgradeSimple () { this.spinner = new Spinner(`${strings.startingUpgradeSimple} %s`) if (this.options.spinner === false) { console.log(strings.startingUpgradeSimple) } else { this.spinner.start() } const output = await powershell.runSimpleUpgrade(this.options.npmVersion) this.spinner.stop(false) console.log('\n') if (output.error) { throw output.error } }
async afterChannelDeleted (channel) { try { const spark = new SparkClient({ token: channel.token }) const webhooks = await spark.webhooksGet() const webhook = webhooks.find(w => w.name === channel.slug) if (!webhook) { return } await spark.webhookRemove(webhook.id) } catch (err) { logger.error(`[Cisco] Error while unsetting the webhook: ${err}`) } }
static async getVendors (req, res) { const channel = await AmazonController.loadChannel(req, res) try { const channelIntegration = new AmazonAlexaChannel() const vendors = await channelIntegration.getVendors(channel) return renderOk(res, vendors.body) } catch (err) { logger.error(`[Amazon Alexa] Error retrieving Vendors: ${err} (${JSON.stringify(err.body)})`) logger.error(err.stack) res.status(500).send(err) } }
async refreshAccessToken (channel) { const { refresh_token } = channel.oAuthTokens try { const response = await lwa.refreshAccessToken( refresh_token, config.amazon_client_id, config.amazon_client_secret) channel.oAuthTokens.access_token = response.access_token await channel.save() } catch (err) { logger.error(`[Amazon Alexa] Error refreshing access token: ${err}`) throw err } }
async afterChannelDeleted (channel) { try { const api = new callr.api(channel.userName, channel.password) await new Promise((resolve, reject) => (api.call('webhooks.unsubscribe', channel.webhookToken) .success(resolve) .error(reject))) } catch (err) { logger.error(`[CallR] Error while unsetting webhook: ${err}`) } }
populateParticipantData (participant, channel) { return new Promise(async (resolve, reject) => { request.get(`https://api.kik.com/v1/user/${participant.senderId}`) .auth(channel.userName, channel.apiKey) .end((err, result) => { if (err) { logger.error(`[Kik] Error when retrieving user info: ${err}`) return reject(err) } participant.data = result.body participant.markModified('data') participant.save().then(resolve).catch(reject) }) }) }
parseIncomingMessage (conversation, message) { const msg = {} const attachment = _.get(message, 'attachments[0]') if (attachment) { if (attachment.contentType.startsWith('image')) { msg.attachment = { type: 'picture', content: attachment.contentUrl } } else if (attachment.contentType.startsWith('video')) { msg.attachment = { type: 'video', content: attachment.contentUrl } } else { logger.warning('[Microsoft] No support for files of type: '.concat(attachment.contentType)) logger.info('[Microsoft] Defaulting to text') if (!message.text || message.text.length <= 0) { logger.error('[Microsoft] No text') throw new StopPipeline() } msg.attachment = { type: 'text', content: message.text } } } else { msg.attachment = { type: 'text', content: message.text } } return msg }
async parseIncomingMessage (conversation, message, opts) { try { // Workaround for passing on the Response Builder since the ASK SDK wraps it into an object // eslint-disable-next-line max-len // https://github.com/alexa/alexa-skills-kit-sdk-for-nodejs/blob/2.0.x/ask-sdk-core/lib/skill/Skill.ts#L93 const alexaResponse = await AmazonAlexa.skill.invoke(message) // Extract msg (for Bot Builder) and responseBuilder (for Alexa response) const { response: { msg, responseBuilder } } = alexaResponse // Delete the current response object delete alexaResponse.response _.set(opts, 'responseBuilder', responseBuilder) _.set(opts, 'alexaResponseTemplate', alexaResponse) return msg } catch (err) { logger.error(`[Amazon Alexa] Error invoking skill: ${err}`) throw err } }
if (accounts.error) return accounts; if (accounts.length === 0) return { error: 'No usernames with the ids could be found.' }; return accounts;
async beforeChannelCreated (channel) { const type = 'sms.mo' const context = { hmac_secret: channel.password, hmac_algo: 'SHA256' } const api = new callr.api(channel.userName, channel.password) try { await new Promise((resolve, reject) => (api.call('webhooks.subscribe', type, channel.webhook, context) .success(async (res) => { channel.webhookToken = res.hash resolve() }) .error(reject))) channel.isErrored = false } catch (err) { logger.error('[CallR] Error while setting webhook', err) channel.isErrored = true } return channel.save() }
async beforeChannelCreated (channel) { try { const spark = new SparkClient({ token: channel.token, webhookUrl: channel.webhook }) const webhook = { name: channel.slug, targetUrl: channel.webhook, resource: 'messages', event: 'created', } const [me] = await Promise.all([ spark.personMe(), spark.webhookAdd(webhook), ]) channel.userName = me.id channel.isErrored = false } catch (err) { logger.error(`[Cisco] Error while setting the webhook: ${err}`) channel.isErrored = true } return channel.save() }
async cancelAllFutureOrders() { let unfinishs = this.__unfinishFutureOrders; if (!_.values(unfinishs).length) return { success: true, message: 'no order to cancel' }; const reqs = ['pair', 'order_id', 'contract_type']; unfinishs = _.map(unfinishs, d => _.pick(d, reqs)); unfinishs = _.groupBy(unfinishs, 'pair'); unfinishs = _.mapValues(unfinishs, d => _.groupBy(d, 'contract_type')); let tasks = _.map(unfinishs, (info, pair) => { return _.map(info, (ds, contract_type) => { const o = { pair, contract_type, order_id: _.map(ds, d => d.order_id) }; return this.cancelFutureOrders(o); }); }); tasks = _.flatten(tasks); const ds = await Promise.all(tasks); const res = { success: [], error: [] }; _.forEach(ds, (d) => { res.success = { ...res.success, ...d.success }; res.error = { ...res.error, ...d.error }; }); return { success: _.keys(res.success), error: _.keys(res.error) }; }
}) } catch (err) { logger.error(`Error while getting raw body from request: ${err}`)
static async loadChannel (req, res) { const connector = await Connector.findOne({ _id: req.params.connectorId, isActive: true }) const channel_slug = req.params.channel_slug if (!connector) { throw new NotFoundError('Connector') } // Load the existing Channel model object let channel try { channel = await Channel.findOne({ slug: channel_slug, connector: connector._id, isActive: true, }) } catch (err) { logger.error(`[Amazon Alexa] Error loading Channel model: ${err}`) res.status(500).send(err) } if (!channel) { throw new NotFoundError('Channel') } return channel }
static async deploy (req, res) { const channel = await AmazonController.loadChannel(req, res) try { const channelIntegration = new AmazonAlexaChannel() await channelIntegration.deploy(channel, req.body) return renderOk(res) } catch (err) { logger.error(`[Amazon Alexa] Error deploying: ${err} (${JSON.stringify(err.body)})`) logger.error(err.stack) res.status(500).send(err) } }