Steem Voice A0.5 - Migration to Google V2 APIsteemCreated with Sketch.

in #utopian-io5 years ago

Steem Voice

Github repository
Author

Hello everyone! Welcome back to the fifth development update of the Steem Voice app. This update is quite an interesting one because Steem Voice is now using V2 API thanks to the new update in flask-assistant which is probably the core of this project. This migration could really help optimize the project and overcome a lot of the issues I faced developing Steem Voice. I altered a lot of the commands to be compatible with the new migration. I also did a whole lot of testing, checking every single command in the app.

New Features

V2 Migration

I hate to bore you with all the little details that I changed including the ones I changed in Dialog flow. To summarize it all here are some of the things that I changed.

app.config['ASSIST_ACTIONS_ON_GOOGLE'] = True # To enable Rich Messages

Is now

app.config['INTEGRATIONS'] = ['ACTIONS_ON_GOOGLE'] # To enable Rich Messages

V2 also requires you to add the project's ID so I made it into an environment variable like so:

assist = Assistant(app, route='/api', project_id=os.environ.get('project_id'))

Also img_alt is no longer required and linkTitle is now link_title
You can check out the migration's commit for more details.

Added a downvote command

Even though all that tweaking and testing took way more time that I thought, I couldn't leave the update there. So I made 3 new commands.
The down vote command is embedded into the upvote one added in the last update like so: (Thanks @emrebeyler for the suggestion)

def r_upvote(number,vote):
    if (int(number)<=100) and (0<=int(number)): 
        global percent, votetype
        votetype = vote
        if votetype == 'upvote':
            percent = int(number)
            return ask('Would you like to confirm this upvote: %s percent' % percent).suggest('Yes','No')
        else:
            percent = -int(number)
            return ask('Would you like to confirm this downvote: %s percent' % (-1*percent)).suggest('Yes','No')
    else:
        return ask('Please make sure to enter a valid percent')

As you can see I added a variable called vote type which distinguishes if it's an upvote or a downvote. I also had to modify the broadcast function to make the conversation more "legit":

def r_broadcastupvote(yon):
    try:
        global percent, posts, Option, votetype
        vote = Vote(sc.me()['name'], posts[Option]["author"], posts[Option]["permlink"], int(percent))
        sc.broadcast([vote.to_operation_structure()])
        if votetype =='upvote':
            return ask('broadcasting upvote to %s' % posts[Option]['title'])
        else:
            return ask('broadcasting downvote to %s' % posts[Option]['title'])
    except: # If the user didn't connect his account
        return ask('Please connect your account before using this command')

Added a who is command

This is a simple command that shows you the name, description and avatar of a specific user. Here's the code for it:

def r_whois(username):
    user = Steemian(username)
    resp = ask('There you go')
    resp.card(title='Name: %s' % user.data["json_metadata"]["profile"]['name'],
          text='Description: %s' % user.data["json_metadata"]["profile"]['about'],
          img_url='https://steemitimages.com/u/'+username+'/avatar',          
            )
    return resp

Here's a video of the command:


Added a reguser command

This command allows new users to register their name in the database so that I can go through them manually and add synoyms to make it easier for the app to catch the username right. For now, I'm saving the database in a localfile called usernames.json. This will surely change into a remote file later when I release the app. With that out of the way, here's the code for it:

def r_reguser():
    try:
        with open('usernames.json') as old:
            database = json.load(old)
        name = {sc.me()['name']:sc.me()['name']}
        database.update(name)
        with open('usernames.json', 'w') as new:
            json.dump(database, new)
        return ask('Done %s was sucessfully added.' % sc.me()['name'] )
    except:
        return ask('Please connect your account before using this command')

Here's a video of the command:


How to install

You can follow the guide I wrote in the third update

Roadmap

Next step is start preparing for the release of the app like organizing the code and finding solutions to potential problems...

How to contribute?

Everyone is welcome to aid. You can contribute to the development of this project by creating a pull request to my repository. You can also get in touch with me on Discord at Fancybrothers#7429 or on Steem.chat at fancybrothers or simply leave your idea down below.

My Github account: https://github.com/Fancybrothers

Sort:  

Thank you for your contribution. This is defintely a unique piece of work.

  1. It is in general a good practise to submit your changes in a separate branch, create a PR and merge it - so you have a much cleaner commit logs in your master branch - and also it is easier to revert a set of changes if you decide to later.
  2. It will be a good idea to extract the set of commands such as ask('Would you like to confirm this upvote: %s... and put them in a separate class, file or module, so that it will be easier to maintain.
  3. I notice that the Google assistant is slightly laggy, any reasons/causes?
  4. Also, you are using general exception e.g. try .. catch for some known issues, such as user not registered. General Exception is bad.

Looking forward to your next contribution!

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

Thank you for your review, @justyy! Keep up the good work!

Hi @fancybrothers!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
Feel free to join our @steem-ua Discord server

Hey, @fancybrothers!

Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Get higher incentives and support Utopian.io!
Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Coin Marketplace

STEEM 0.30
TRX 0.12
JST 0.033
BTC 64386.10
ETH 3142.17
USDT 1.00
SBD 3.98