Skip to content

Instantly share code, notes, and snippets.

View RedRussianBear's full-sized avatar

Mikhail Khrenov RedRussianBear

View GitHub Profile
// Import Botkit and Google Cloud Language API
const Botkit = require('botkit');
const language = require('@google-cloud/language');
// Instantiates a GCPL client
const client = new language.LanguageServiceClient();
// Create the Botkit controller
const controller = Botkit.sparkbot({
public_address: process.env.public_address,
const response_emoji = ['😭', '😢', '😞', '😐', '🙂', '😃', '😄'];
controller.on('direct_mention,direct_message', function(bot, message) {
if(message.text) {
const document = {
content: message.text,
type: 'PLAIN_TEXT',
};
client.analyzeSentiment({document: document})
# Environment Config
access_token=YOUR_CISCO_BOT_TOKEN
public_address=PUBLIC_GLITCH.ME_ADDRESS
secret=RANDOM_STRING
studio_token=
PORT=
GOOGLE_APPLICATION_CREDENTIALS=~/.data/credentials.json
"dependencies": {
...
"@google-cloud/language": "2.0.0"
},
// Import Botkit
const Botkit = require('botkit');
// Imports the Google Cloud client library
const language = require('@google-cloud/language');
// Instantiates a client
const client = new language.LanguageServiceClient();
// Create the Botkit controller
const controller = Botkit.sparkbot({
# Environment Config
access_token=YOUR_CISCO_TOKEN
public_address=GLITCH_DOMAIN
secret=RANDOM_STRING
studio_token=
PORT=
weather_token=YOUR_OPENWEATHERMAP_KEY
controller.on('direct_mention', function(bot, message) {
if(message.text){
const query = message.text.trim();
if(query.includes('help')) {
bot.reply(message, 'Hi! I\'m Weatherbot! I can get you the weather in any city!');
bot.reply(message, 'Usage: @weather-bot [city] or @weatherbot [city],[country code]');
}
else {
bot.reply(message, 'Let me check...');
getWeatherFor(bot, message, query);
function getWeatherFor(bot, message, city) {
const query = 'http://api.openweathermap.org/data/2.5/weather?q=' + encodeURI(city)
+ '&appid=' + process.env.weather_token;
http.get(query, (res) => {
const { statusCode } = res;
const contentType = res.headers['content-type'];
res.setEncoding('utf8');
// Import Botkit
const Botkit = require('botkit');
// Import Node HTTP for API requests
const http = require('http');
// Create the Botkit controller
const controller = Botkit.sparkbot({
public_address: process.env.public_address,
access_token: process.env.access_token,
// Import Botkit
const Botkit = require('botkit');
// Import Node HTTP for API requests
const http = require('http');
// Create the Botkit controller
const controller = Botkit.sparkbot({
public_address: process.env.public_address,
access_token: process.env.access_token,