heyoo icon indicating copy to clipboard operation
heyoo copied to clipboard

save input from the users and send another message

Open nir-flow opened this issue 3 years ago • 1 comments

First of all I must say that the project is amazing!! I need to send a message, then save the input that comes from the user, then send another message and again save the input. How can I do this?

nir-flow avatar Aug 15 '22 13:08 nir-flow

You can write your logic to save data as a separate function as shown below;

def save(name:str,name:str, message:str):
    pass
    # Your logic to save the data stays here

And then call it on if message_type==text block on your web hook logic just as shown below, with this you should be able to do that.

@app.route('/')
def hook():
    # Other pieces of code lives here 
            if message_type == "text":
                message = messenger.get_message(data)
                name = messenger.get_name(data)
                logging.info("Message: %s", message)
                save(mobile, name, message)
                messenger.send_message(f"Hi {name}, nice to connect with you", mobile)

Kalebu avatar Aug 15 '22 14:08 Kalebu

hi @Kalebu , I also wondered how can we log API request or in general if I am calling an API through a library then what is a general practise , How can we log API request response.... like sqlalchemy with sqlite3 ?

jay-patel-cognoai avatar Aug 22 '22 08:08 jay-patel-cognoai

Hi @jay-patel-cognoai, Are you talking about logging the hook response or heyoo methods response?

If its hook, It is already included in the hook on how to log it

   # Handle Webhook Subscriptions
    data = request.get_json()
    logging.info("Received webhook data: %s", data)

But if you're talking about specific heyoo message like send_message, they do return a json response by default so you can easily log the response like this;

>>> r = messenger.send_message('hi there', '34xxxx')
>>> print(r)

You can then save the log whenever you want whether to log file, text file, or database, Are you also suggesting we should include API Response logging by default to the library right?

Kalebu avatar Aug 23 '22 08:08 Kalebu

Just wanted to know do libraries ever use any kind of database for their internal functioning.

jay-patel-cognoai avatar Aug 23 '22 13:08 jay-patel-cognoai

Well it depends on the design choices of a particular library, For heyoo we don't

I will mark this issue #20 as resolved

Kalebu avatar Aug 23 '22 13:08 Kalebu