navigationGo.pngQuick Navigation
allprojects32.pngAll projects
hardware32.pngHardware
links32.pngLinks

favoriteStar32.pngTop projects
Alan numitron clock
Clapclap 2313/1386
SNES Pi Webserver
USB Volume/USB toys
Smokey amp
Laser cutter
WordClock
ardReveil v3
SNES Arcade cabinet
Game boy projects
cameleon
Home Presence Detector

github32.pngGitHub
AlanFromJapan

navigationMail.pngContact me

alanfjmail.png
3flags.pngWho's Alan?


Akizukidenshi
Elec-lab
Rand Nerd Tut
EEVblog
SpritesMods
Switch-science
Sparkfun
Suzusho
Datasheet Lib
Reddit Elec
Ermicro
Carnet du maker (fr)
Marutsu
ATmel blog (defunct)

line chatbot

This is a new Template for line chatbot!

Presentation

Principle

Started that in December 2016, idea would be a line chatbot that can do some domotics... First we'll work with the Messaging API of Line.

Points of interest

Implementation

Basics: get a service running and plugged in Line

  • Create a business account, as a developer
  • Make a Channel, but for that you'll need a Provider
  • On the backend server, make a user linebot : sudo adduser --disabled-login linebot
  • If python pip is not here, you can :python -m ensurepip --default-pip or curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py;python get-pip.py or python -m ensurepip --default-pip
  • sudo pip install line-bot-sdk flask
  • git clone https://github.com/line/line-bot-sdk-python
  • Make yourself a DNS name, Duck DNS is fantastic and free (thanks guys!)
  • Now you need a certificate, so use certbot (let's encrypt thanks for your free service!) for that. I tried many options, but ended by using the manual method: sudo certbot certonly --manual -d myserver.duckdns.org
    you'll need to run a parallel simple webserver, but it's all explained on the screen, just read it, you'll end up with you 2 .pem certificate files. You want that key file and your fullchain.pem that is stored in /etc/letsencrypt/live/myserver.duckdns.org/. You can use the privkey that is there too, it's the same as the key file you generated above.
  • mkdir -p /tmp/certbot/public_html/.well-known/acme-challenge
    cd /tmp/certbot/public_html
    printf "%s" ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX > .well-known/acme-challenge/ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
    
    sudo $(command -v python2 || command -v python2.7 || command -v python2.6) -c "import BaseHTTPServer, SimpleHTTPServer; \
    s = BaseHTTPServer.HTTPServer(('', 80), SimpleHTTPServer.SimpleHTTPRequestHandler); \
    s.serve_forever()" 
    
  • You should now be able to run the basic samples of Line, after editing the code as below to enable listening to outside request (host="0.0.0.0") and enabling the certificates:
  • if __name__ == "__main__":
        app.run(host="0.0.0.0", ssl_context=('fullchain.pem', 'privkey.pem'))
    
  • Now go to Line website and go to your channel then provider and edit the 2 webhooks settings:
  • Use webhooks: set to Enabled
  • Webhook URL: put the url of your callback service, ie https://myserver.duckdns.org/callback You can even test, though it fails for me with the sample "flask-echo" but it works when you call it by talking to your line bot!
  • Victory, as you're here, you have a beta prototype working. Good job, go grab a beer. Yes you can, you deserve it.

    Basics: as a docker!

    I need a pretext to study docker, sounds about right. I will detail it here.

    Natural Language Processing : SpaCy

  • Install Spacy, Python 2.x, in a Virtualenv, and English catalog
  • python -m pip install -U virtualenv
    virtualenv .env
    source .env/bin/activate
    pip install -U spacy
    python -m spacy download en
    

    Schematics

    Source code

    Pictures

    Links

    Sites you'll need

  • Line developer portal: https://developers.line.biz/console/
  • Helpful sources

  • Official getting started with Messaging API https://developers.line.biz/en/docs/messaging-api/getting-started/
  • Official python SDK https://github.com/line/line-bot-sdk-python
  • Certbot (Let's encrypt) and Flask
  • NLP
  • SpaCy the trendy python lib https://spacy.io/usage/
  • Inspiration

    All content on this site is shared under the MIT licence (do what u want, don't sue me, hat tip appreciated)
    electrogeek.cc ~ Formerly known as Kalshagar.wikispaces.com (AlanFromJapan [2009 - 2019])