Skip to content

Commit

Permalink
Release v1.0-beta
Browse files Browse the repository at this point in the history
  • Loading branch information
Elizabeth Martín Campos committed Jul 31, 2018
1 parent eeadc32 commit b866be6
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 100 deletions.
92 changes: 50 additions & 42 deletions handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async function searchQuery(coordinates, config, callback) {
let configDB = new ddbGeo.GeoDataManagerConfiguration(ddb, config.table)
configDB.hashKeyLength = config.hashLength
let searchDB = new ddbGeo.GeoDataManager(configDB)

// Increment the radius until results are found
for (let radius = config.radius, foundResult = false; radius <= config.radiusLimit && foundResult === false; radius = radius*2) {
await searchDB.queryRadius(Object.assign({
Expand Down Expand Up @@ -255,7 +255,7 @@ bot.command('start', 'help', (msg, reply) => {

// Show bot license and info
bot.command('info', (msg, reply) => {
reply.disablePreview().markdown('*NearBot Madrid*\nVersión 1.0 (30/07/2018)\n\nTiempo de ejecución Node.js v8.10 junto al framework para bots [Botgram](https://github.com/botgram/botgram) v2.1.0.\n\nEste bot es software libre y está licenciado bajo [GNU AGPL v3.0](https://github.com/elizabeth-dev/NearBot-Madrid/blob/master/LICENSE.md), lo cuál significa que puedes modificarlo y redistribuirlo libremente conforme a los términos de la licencia. Asimismo, se distribuye sin ninguna garantía ni responsabilidad.\n\nPuedes obtener más informacion sobre el funcionamiento del bot, su código fuente, y su licencia en su repositorio de GitHub [NearBot-Madrid](https://github.com/elizabeth-dev/NearBot-Madrid).\n\nAdemás, puedes contactar con su creadora por [Twitter](https://twitter.com/Eli_coptero_), o por [Telegram](tg://user?id=74460537).\n\n_Elizabeth Martín Campos_\nhttps://eli.zabeth.es/')
reply.disablePreview().markdown('*NearBot Madrid*\nVersión 1.0-beta (30/07/2018)\n\nTiempo de ejecución Node.js v8.10 junto al framework para bots [Botgram](https://github.com/botgram/botgram) v2.1.0.\n\nEste bot es software libre y está licenciado bajo [GNU AGPL v3.0](https://github.com/elizabeth-dev/NearBot-Madrid/blob/master/LICENSE.md), lo cuál significa que puedes modificarlo y redistribuirlo libremente conforme a los términos de la licencia. Asimismo, se distribuye sin ninguna garantía ni responsabilidad.\n\nPuedes obtener más informacion sobre el funcionamiento del bot, su código fuente, y su licencia en su repositorio de GitHub [NearBot-Madrid](https://github.com/elizabeth-dev/NearBot-Madrid).\n\nAdemás, puedes contactar con su creadora por [Twitter](https://twitter.com/Eli_coptero_), o por [Telegram](tg://user?id=74460537).\n\n_Elizabeth Martín Campos_\nhttps://eli.zabeth.es/')
})

// Show what's new in the last update
Expand All @@ -271,14 +271,15 @@ bot.command('metro', 'cercanias', 'metroligero', 'transporte', 'fuente', 'bici',
bot.location((msg, reply) => {
let coordinates = [msg.latitude, msg.longitude]
if (msg.reply) { // If the location is a reply to a message (serverless tricks)

let config = { filter: {} }

if (RegExp('^' + regex.mediosTransporte).test(msg.reply.text)) { // If message requests a transport station
// Initialize the DB client
config.table = 'NearBot_Madrid_Transporte'
config.hashLength = 8
config.radius = 200
config.radiusLimit = 3200
config.radius = 300
config.radiusLimit = 2400

// Check which type of station is the user requesting
switch (true) {
Expand Down Expand Up @@ -338,8 +339,8 @@ bot.location((msg, reply) => {
// Initialize the DB client
config.table = 'NearBot_Madrid_Supermercado'
config.hashLength = 9
config.radius = 200
config.radiusLimit = 3200
config.radius = 500
config.radiusLimit = 4000

switch (true) {
case RegExp('^' + regex.carrefour).test(msg.reply.text):
Expand Down Expand Up @@ -376,7 +377,7 @@ bot.location((msg, reply) => {
// Initialize the DB client
config.table = 'NearBot_Madrid_Fuente'
config.hashLength = 9
config.radius = 100
config.radius = 400
config.radiusLimit = 1600

searchQuery(coordinates, config, (results) => {
Expand All @@ -386,8 +387,8 @@ bot.location((msg, reply) => {
// Initialize the DB client
config.table = 'NearBot_Madrid_Bici'
config.hashLength = 8
config.radius = 100
config.radiusLimit = 800
config.radius = 300
config.radiusLimit = 1200

searchQuery(coordinates, config, (results) => {
processBici(coordinates, reply, results)
Expand All @@ -396,8 +397,8 @@ bot.location((msg, reply) => {
// Initialize the DB client
config.table = 'NearBot_Madrid_Aseo'
config.hashLength = 9
config.radius = 100
config.radiusLimit = 800
config.radius = 400
config.radiusLimit = 1600

searchQuery(coordinates, config, (results) => {
processAseo(coordinates, reply, results)
Expand All @@ -423,15 +424,26 @@ bot.callback((query, next) => {
}

let reply = bot.reply(data.i)

let config = { filter: {} }
switch (data.t) {
case 'menu':
reply.inlineKeyboard([
[{ text: 'Transporte', callback_data: JSON.stringify({ t: 'tte_menu', c: data.c, i: data.i }) }],
[{ text: 'Supermercado', callback_data: JSON.stringify({ t: 'spr_menu', c: data.c, i: data.i }) }],
[{ text: 'BiciMAD', callback_data: JSON.stringify({ t: 'bici', c: data.c, i: data.i }) }],
[{ text: 'Fuente de agua', callback_data: JSON.stringify({ t: 'fuente', c: data.c, i: data.i }) }],
[{ text: 'Aseo', callback_data: JSON.stringify({ t: 'aseo', c: data.c, i: data.i }) }]
]).editReplyMarkup(query.message).then(query.answer())
break
case 'tte_menu':
reply.inlineKeyboard([
[{ text: 'Metro', callback_data: JSON.stringify({ t: 'mtro', c: data.c, i: data.i }) }],
[{ text: 'Cercanías', callback_data: JSON.stringify({ t: 'cerc', c: data.c, i: data.i }) }],
[{ text: 'Metro ligero', callback_data: JSON.stringify({ t: 'mlig', c: data.c, i: data.i }) }],
[{ text: 'Cualquiera', callback_data: JSON.stringify({ t: 'tte', c: data.c, i: data.i }) }]
]).editReplyMarkup(query.message)
[{ text: 'Cualquiera', callback_data: JSON.stringify({ t: 'tte', c: data.c, i: data.i }) }],
[{ text: '<- Volver', callback_data: JSON.stringify({ t: 'menu', c: data.c, i: data.i }) }]
]).editReplyMarkup(query.message).then(query.answer())
break
case 'mtro':
// Initialize the DB client
Expand All @@ -444,8 +456,8 @@ bot.callback((query, next) => {
ExpressionAttributeValues: { ':type': {'S': 'Metro' } }
}
}
config.radius = 200
config.radiusLimit = 3200
config.radius = 300
config.radiusLimit = 2400

// Query the DB and process the results
searchQuery(data.c, config, (results) => {
Expand All @@ -463,8 +475,8 @@ bot.callback((query, next) => {
ExpressionAttributeValues: { ':type': {'S': 'Cercanías' } }
}
}
config.radius = 200
config.radiusLimit = 3200
config.radius = 300
config.radiusLimit = 2400

// Query the DB and process the results
searchQuery(data.c, config, (results) => {
Expand All @@ -482,8 +494,8 @@ bot.callback((query, next) => {
ExpressionAttributeValues: { ':type': {'S': 'Metro Ligero' } }
}
}
config.radius = 200
config.radiusLimit = 3200
config.radius = 300
config.radiusLimit = 2400

// Query the DB and process the results
searchQuery(data.c, config, (results) => {
Expand All @@ -494,8 +506,8 @@ bot.callback((query, next) => {
// Initialize the DB client
config.table = 'NearBot_Madrid_Transporte'
config.hashLength = 8
config.radius = 200
config.radiusLimit = 3200
config.radius = 300
config.radiusLimit = 2400

// Query the DB and process the results
searchQuery(data.c, config, (results) => {
Expand All @@ -506,14 +518,15 @@ bot.callback((query, next) => {
reply.inlineKeyboard([
[{ text: 'Carrefour', callback_data: JSON.stringify({ t: 'crf', c: data.c, i: data.i }) }],
[{ text: 'Mercadona', callback_data: JSON.stringify({ t: 'mrc', c: data.c, i: data.i }) }],
[{ text: 'Cualquiera', callback_data: JSON.stringify({ t: 'spr', c: data.c, i: data.i }) }]
]).editReplyMarkup(query.message)
[{ text: 'Cualquiera', callback_data: JSON.stringify({ t: 'spr', c: data.c, i: data.i }) }],
[{ text: '<- Volver', callback_data: JSON.stringify({ t: 'menu', c: data.c, i: data.i }) }]
]).editReplyMarkup(query.message).then(query.answer())
break
case 'crf':
config.table = 'NearBot_Madrid_Supermercado'
config.hashLength = 9
config.radius = 200
config.radiusLimit = 3200
config.radius = 500
config.radiusLimit = 4000
config.filter = {
QueryInput: {
FilterExpression: '#marca = :type',
Expand All @@ -529,8 +542,8 @@ bot.callback((query, next) => {
case 'mrc':
config.table = 'NearBot_Madrid_Supermercado'
config.hashLength = 9
config.radius = 200
config.radiusLimit = 3200
config.radius = 500
config.radiusLimit = 4000
config.filter = {
QueryInput: {
FilterExpression: '#marca = :type',
Expand All @@ -546,8 +559,8 @@ bot.callback((query, next) => {
case 'spr':
config.table = 'NearBot_Madrid_Supermercado'
config.hashLength = 9
config.radius = 200
config.radiusLimit = 3200
config.radius = 500
config.radiusLimit = 4000

searchQuery(data.c, config, (results) => {
processSuper('supermercado', data.c, reply, results)
Expand All @@ -556,8 +569,8 @@ bot.callback((query, next) => {
case 'bici':
config.table = 'NearBot_Madrid_Bici'
config.hashLength = 8
config.radius = 100
config.radiusLimit = 800
config.radius = 300
config.radiusLimit = 1200

searchQuery(data.c, config, (results) => {
processBici(data.c, reply, results)
Expand All @@ -566,7 +579,7 @@ bot.callback((query, next) => {
case 'fuente':
config.table = 'NearBot_Madrid_Fuente'
config.hashLength = 9
config.radius = 100
config.radius = 400
config.radiusLimit = 1600

searchQuery(data.c, config, (results) => {
Expand All @@ -576,8 +589,8 @@ bot.callback((query, next) => {
case 'aseo':
config.table = 'NearBot_Madrid_Aseo'
config.hashLength = 9
config.radius = 100
config.radiusLimit = 800
config.radius = 400
config.radiusLimit = 1600

searchQuery(data.c, config, (results) => {
processAseo(data.c, reply, results)
Expand All @@ -586,23 +599,18 @@ bot.callback((query, next) => {
default:
console.log(data)
console.log(query)
query.answer()
}
})

bot.stop()

module.exports.telegram = (event, context, callback) => {
bot.processUpdate(event.body) // Botgram processes incoming request
bot.processUpdate(JSON.parse(event.body)) // Botgram processes incoming request
const response = {
statusCode: 200,
body: JSON.stringify({
message: 'NearBot v1.0',
input: event
})
body: JSON.stringify('NearBot v1.0')
}

callback(null, response)

// Use this code if you don't use the http event with the LAMBDA-PROXY integration
// callback(null, { message: 'Go Serverless v1.0! Your function executed successfully!', event });
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nearbot-madrid",
"version": "0.0.0",
"version": "1.0-beta",
"description": "Find nearby places in Madrid easily using Telegram",
"main": "handler.js",
"scripts": {
Expand Down
60 changes: 3 additions & 57 deletions serverless.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
# Welcome to Serverless!
#
# This file is the main config file for your service.
# It's very minimal at this point and uses default values.
# You can always add more config options for more control.
# We've included some commented out config examples here.
# Just uncomment any of them to get that config option.
#
# For full config options, check the docs:
# docs.serverless.com
#
# Happy Coding!

service: NearBot
app: nearbot
tenant: elizabethdev
Expand All @@ -19,7 +6,7 @@ provider:
name: aws
runtime: nodejs8.10
region: eu-west-1
endpointType: REGIONAL
#endpointType: REGIONAL

iamRoleStatements:
- Effect: "Allow"
Expand All @@ -46,53 +33,12 @@ functions:
name: ${self:provider.stage}-NearBot_Madrid
description: Madrid instance of NearBot
handler: handler.telegram
memorySize: 128
memorySize: 256
events:
- http:
path: dev-NearBot_Madrid
path: NearBot_Madrid
method: post

# The following are a few example events you can configure
# NOTE: Please make sure to change your handler code to work with those events
# Check the event documentation for details
# events:
# - http:
# path: users/create
# method: get
# - s3: ${env:BUCKET}
# - schedule: rate(10 minutes)
# - sns: greeter-topic
# - stream: arn:aws:dynamodb:region:XXXXXX:table/foo/stream/1970-01-01T00:00:00.000
# - alexaSkill: amzn1.ask.skill.xx-xx-xx-xx
# - alexaSmartHome: amzn1.ask.skill.xx-xx-xx-xx
# - iot:
# sql: "SELECT * FROM 'some_topic'"
# - cloudwatchEvent:
# event:
# source:
# - "aws.ec2"
# detail-type:
# - "EC2 Instance State-change Notification"
# detail:
# state:
# - pending
# - cloudwatchLog: '/aws/lambda/hello'
# - cognitoUserPool:
# pool: MyUserPool
# trigger: PreSignUp

# Define function environment variables here
# environment:
# variable2: value2

# you can add CloudFormation resource templates here
#resources:
# Resources:
# NewResource:
# Type: AWS::S3::Bucket
# Properties:
# BucketName: my-new-bucket
# Outputs:
# NewOutput:
# Description: "Description for the output"
# Value: "Some output value"

0 comments on commit b866be6

Please sign in to comment.