1

I'm trying to create my first chatbot that I want to use for my home automation project.

This might sound stupid and maybe this is not the way to go but I would like to have your opinion and perhaps a way to make it work.

I want to be able to ask my bot what is my location and I want it to run my python code that returns my current location and then get an answer with that.

This is my location.py

from pyicloud import PyiCloudService
import googlemaps
import aiml


api_key = "##################3"

gmaps = googlemaps.Client(key= api_key)

api = PyiCloudService('###email####','###password###')

longitude = api.iphone.location()['longitude']
latitude = api.iphone.location()['latitude']


current_location  = gmaps.reverse_geocode((latitude, longitude))
street = current_location[0]['address_components'][1]['long_name']
house_number = current_location[0]['address_components'][0]['long_name']


def get_location():
    current_location = ('%s,%s' % (street, house_number))
    return current_location

Now I don know how to get this into my aiml file.

<?xml version="1.0" encoding="UTF-8"?>
 <aiml>
<category>
<pattern>WHAT IS MY LOCATION</pattern>
<template>??????</template>
</category>

</aiml>

I hope this makes some sense :)

Thanks for the help!

Tiago São José
  • 292
  • 3
  • 5
  • 12

1 Answers1

0

If your location is Chicago, You can use kernel.setPredicate("location", "Chicago") in Python and then put out the value in AIML like this:

<category>
<pattern>WHAT IS MY LOCATION</pattern>
<template>Your location: <get name="location"></get></template>
</category>

Check out an examples here.

Trewq
  • 3,187
  • 6
  • 32
  • 50