Whatsapp bot python代码


以下示例是关于Python中包含Whatsapp bot python代码用法的示例代码,想了解Whatsapp bot python代码的具体用法?Whatsapp bot python代码怎么用?Whatsapp bot python代码使用的例子?那么可以参考以下相关源代码片段来学习它的具体使用方法。

[英]:whatsapp bot python code源码类型:Python
from flask import Flask
from googlesearch import search
import requests
from twilio.twiml.messaging_response import MessagingResponse
app = Flask(__name__)
@app.route("/", methods=["POST"])
# chatbot logic
def bot():
    # user input
    user_msg = request.values.get('Body', '').lower()
    # creating object of MessagingResponse
    response = MessagingResponse()
    # User Query
    q = user_msg + "geeksforgeeks.org"
    # list to store urls
    result = []
    # searching and storing urls
    for i in search(q, tld='co.in', num=6, stop=6, pause=2):
    # displaying result
    msg = response.message(f"--- Result for '{user_msg}' are  ---")
    msg = response.message(result[0])
    msg = response.message(result[1])
    msg = response.message(result[2])
    msg = response.message(result[3])
    msg = response.message(result[4])
    return str(response)
if __name__ == "__main__":