program that send wtsp message - python

I'm trying to create a python program that checks a condition for example if the room temperature is above 20 degrees and informs the user by sending a WhatsApp message. the program will be on the user's computer and it's not necessary to have the wtsp account on it. I found a lot of sites that do this thing like nexmo but they are paid. I wanna know how to send the wtsp message but free.

Related

WhatsApp bot in python

I'm trying to make a simple WhatsApp bot using python. But the bot doesn't send the message after it writes the automated message.
This is the code I have written
import pywhatkit
pywhatkit.sendwhatmsg("+20100081978767","Whatsapp bot",5,24)
The reason the message is not sent, is because of the time you set. Have a look at the parameters -
Syntax: pywhatkit.sendmsg(“receiver mobile number”,”message”,hours,minutes)
Parameters:
Receiver mobile number: The Receiver’s mobile number must be in string format and the country code must be mentioned before the mobile number.
Message: Message to be sent(Must be in string format).
Hours: This module follows the 24 hrs time format.
Minutes: Mention minutes of the scheduled time for the message(00-59).
Check this
So, in your code, pywhatkit.sendwhatmsg("+20100081978767", "Whatsapp bot",5,24), 5 and 24 actually means that the message will be sent at 5:24 am tomorrow.
So, try changing time so that you can send the message today.

How do I save/load Bot Framework session information to/from the local disk?

I have a question about a Microsoft Teams Python bot. If the bot has been added to some personal chats and group chats and I restart the bot, sometimes the bot needs to be added to the chats again. So I want to make bot sessions.
Is it possible to make a bot session in Microsoft Teams? I want to store session information on the local disk, and then have the bot load that data when it starts.
My bot code is very similar to this sample.
Thank you for your help.
Updated:
Like I said my bot code is very similar to this sample, but a bit different. Because of this I created an example for this question. First of all I create a bot in Azure and set up it.
After this, in my bot's config.py file I set up the port and Microsoft app ID and password (generated by clicking the "Manage" button).
import os
""" Bot Configuration """
class DefaultConfig:
""" Bot Configuration """
PORT = 3978
APP_ID = os.environ.get("MicrosoftAppId", "sadsadsadasd")
APP_PASSWORD = os.environ.get("MicrosoftAppPassword", "asdasdasdasdasd")
After this I execute the command ngrok http 3978 and put the generated endpoint in the Azure bot configuration. To register the bot as an application, I use App Studio in Teams. After I do that, I just to need run the bot in CMD so I run a command like python run.py
After I run the bot, I can add it in the channel and run commands and functions that I created in the code.
This is just an example of how I set up the bot. The main bot is on a Linux server.
Here is why I want to make the bot keep session information and load it after the server or bot was restarted. Sometimes after I restart the bot or server it is no longer in the chat or team. In the future I want make some kind of commands and execute them using a cron job or something like that.
If the bot disappears from a chat then I can't use bot commands in that chat. For example, I add two bots in a chat. After I restart one of them I can't get any response from it like in the picture below.
And with # I can't see the bot.
I have an idea. After I add the bot in the chat I get this in the console:
Adding new conversation to the list: {'additional_properties': {}, 'activity_id': '123215513', 'user': <botbuilder.schema._models_py3.ChannelAccount object at 0x0000027C0ED60>, 'bot': <botbuilder.schema._models_py3.ChannelAccount object at 0x0000027Cs2FD0>, 'conversation': <botbuilder.schema._models_py3.ConversationAccount object at 0x0000027C0400>, 'channel_id': 'msteams', 'locale': 'en-US', 'service_url': 'https://smba.trafficmanager.net/emea/'}
Formatted:
{
"additional_properties": {},
"activity_id": "123215513",
"user": <botbuilder.schema._models_py3.ChannelAccount object at 0x0000027C0ED60>,
"bot": <botbuilder.schema._models_py3.ChannelAccount object at 0x0000027Cs2FD0>,
"conversation": <botbuilder.schema._models_py3.ConversationAccount object at 0x0000027C0400>,
"channel_id": "msteams",
"locale": "en-US",
"service_url": "https://smba.trafficmanager.net/emea/"
}
So if I store this information and then load it when I start the bot, maybe it will work?
There is an option inside a bot to save a transcript of the conversation, but that's kind of unrelated. Basically, the important thing to know is that you don't need to store anything your side - from the user perspective, the entire conversation history is preserved in the Teams client, and from the perspective of your bot, storing the entire conversation history doesn't really gain you anything - user state is more relevant than conversation history. This would be storing an object in a persistence you choose (e.g. database, nosql store, azure blobs, whatever), but it would be state you choose to store for the user (basically whatever properties make sense to store for your app, in a kind of "User" collection). This is definitely a possible and often necessary concept, and this link will be useful for you: https://learn.microsoft.com/en-us/azure/bot-service/bot-builder-concept-state?view=azure-bot-service-4.0
It's important to know though that this is a separate idea from sending a message on a defined schedule (e.g. Cron) to a user. For this to work, you need to read up on a concept called "Proactive Messaging". I have a sample on the Teams PnP gallery specifically dealing with it (code only in Node and Dotnet - no python I'm afraid, but hopefully it's useful for you). See here for that. Note that at the bottom of this link is a list of further reading on the topic as well.
Where the two above ideas come together is that you need to store certain state about the user to be able to send the proactive message later. In the sample I link to, I show how to get the settings you need to send the proactive message, but I've not included the concept of saving them to a data store - that's up to your own implementation inside your bot (e.g. SQL Azure, MongoDb, blob, whatever).
Also important to note (and I think part of the confusion and in fact part of why I wrote the sample) - your proactive code does not need to live in the same set of code as your bot! Your bot could be a web service running somewhere, and your proactive code an Azure Function/Lambda/similar.
Like Hilton said, it's a bad idea to try and save bot state to the local disk. Also, there's no need for that. Both Hilton and I have linked to documentation that should help you understand how bot state is meant to be saved.
I cannot reproduce the problem you're encountering where the bot gets removed from Teams chats. The problem sounds impossible anyway, based on how Teams works and how bots work. Teams should have no way of knowing whether your bot is started or stopped. It's possible that your server is set up to manually uninstall the bot from Teams conversations based on when the bot starts and stops, but that would still be very strange. I'm willing to continue troubleshooting this with you, but I thought I'd post an answer now in case you'd like to award your bounty to someone before it expires.

Multiplayer call to Telegram bot

I'm writing a telegram-bot. It checks the email box(common to all), and if it finds the set parameters then returns some information to the user and delete this email that contains this parameters. So the problem is this: when I call this bot alone, everything's allright, but if I cal it from several accounts at the same time, it doesn't work correctly. It either doesn't send the information, or sends it incorrectly. It sends the info which belongs to other user. I can't solve this? Can anybody advise me somethin? Sorry for my Ruslish)))

How to send multiple delayed responses from Python Webhook once an intent is been triggered?

I want to send multiple, delayed responses from the webhook written in python, once an intent is been triggered by the user. First response I want immediately after triggering the intent and another response I want after some processing to be performed on top of the user utterance.
For example:
User : I want my account balance.
BOT : Please tell your account number for details.
User : my account number is 218497234.
BOT : Hold-on a bit we are fetching your details.
BOT : Welcome John, your account balance is $70000.
In the above example, this is a bank-bot, which replies to user queries. Currently fetching-up account balance for a user supplying account number. The last two responses from the BOT are from the webhook when say "account_balance_check" intent is been triggered. First response is immediate, asking the user to be patient and wait for the account details , while the second response is after fetching the account details from a db using account number.
Another way could be to trigger response from the bot, without utterance from the user. In the above case, is there anyway, bot itself can send response to user after telling him to wait? Please note that after telling user to wait, we don't want user utterance to trigger second response.
Unfortunately, you cannot do that in Dialogflow because once you send the response then your agent will not be able to send the response without any user input or event call.
Here is an answer if your process does not take a long time. Once you get the user request, send them the waiting message with the "OK" suggestion. Once the user clicks on the suggestion, you can show the response. Also, process the request with some API and save your data in a common file that you can access through both API and agent and then show the response to the user from the file.

Sending a message with PRAW but the receiving account does not ever get the message

I'm trying for the first time using APIs with Python. I'm using PRAW. I've wrote a stupid easy script trying to send a message from one account to another. I'm prompted to login and enter the captcha, but then the receiving account does not ever get the message. What am I doing wrong? I need to get the foundations down to be able to progress onto a more complicated program that implements some logic and other methods.
import praw
r = praw.Reddit('PRAW related-question monitor by u/testpurposes v 1.0.')
r.login()
user = 'krumpqueen'
msg = 'Hello'
r.user.send_message(user, msg)
Your code appears to be correct. The r.user.send_message() takes two arguments. The first is the user to receive the messages and the second is the actual message. So, your code is accurate. However, you shouldn't be receiving a captcha all the time. Try entering your reddit login info in the r.login() method. It should look something like r.login('username', 'password'). You might also see how much karma the account has. Your script may not be making it all the way through because of low karma.
You're sending the message to yourself with subject 'krumpqueen'.
Try:
r.send_message(user, 'SOME SUBJECT', msg)

Categories

Resources