I have made a website , and there are users in it who can send and receive messages to each other, i need to develop a mechanism in which when message is send to a user & if user is login it shows him a message that you have received a message without refreshing the page or fetching from database if message received . just like it is working in facebook and many other sites actually i want to make a chat between 2 users.
Related
Hi I have a program in python that generates results every one hour. The result can be of anything.This program will run in local machine or in the virtual private network.
I have two requirements
1. Send this python generated result to one telegram group [Group name "ourworld"](created by me) automatically without user intervention . (I have desktop telegram client running or web.telegram.org running in the same system)
Send this result to gmail group email ID.
what are the methods available to achieve this requirement .Is there any working code available to do this job .Please share the info and details.
Edit:
The Issue that i am facing :
1.created a Bot using BotFather.
2.Adding this Bot to my Group ,Here i get an error could not add an member So added the Bot as admin in the group
3.Token of the BOT noted down.
4. Trying to get ChatId
in this forum (https://web.telegram.org/#/im?p=g154513121) someone says number after p=g is the chartid ,In my case there is no
number it shows #testingname like this.
Using this approach trying to get the Chat ID https://api.telegram.org/bot738909732:AAE-2l7xAAlYHBXprK_a_bex09g9DMZbbDI/getme
so here 738909732 become a chat Id (in this case why we need seperate
call for the chart id)
here it is true as response coming! Here the chat id is the ID of the my "testingname" no chart id generated for the group.
6.Now packing the URL to see the response i am getting this error.
https://api.telegram.org/bot738909732:AAE-2l7xAAlYHBXprK_a_bex09g9DMZbbDI/sendMessage?chat_id=738909732&text=testing
the output if i run this in browser
{"ok":false,"error_code":400,"description":"Bad Request: chat not
found"} {"ok":false,"error_code":403,"description":"Forbidden: bot
can't send messages to bots"}
How to resolve this issue and make the BOT working .why i am not able to add BOT to my group that says error "Cant Add user"
How to make this telegram group working.
Note : Using BotFather BOT created
In case for sending message to telegram group the above method provided by bipin_s works where the chat_id = -xxxxxx is used.This is correct id followed by - symbol to be used.
For Posting message in the "telegram channel " a minor change needs to be done in the URL.The URL must be framed as below .
url = "https://api.telegram.org/botTokenID/sendMessage?chat_id=#yourChannelChatID&text=message"
Replace the TokenID with your BOT tokenID replace the yourChannelChatID with your channel chart id.Please note that the channel id is not negative id.
the code will look like this
import request
url = "https://api.telegram.org/botXyz:wwwwDFSJSJSAX/sendMessage?chat_id=#telechanneltesting&text=message"
requests.post(url)
Here the "message" as in the URL it will be posted in telegram channel.
How to get channel id ?
Go to https://web.telegram.org/#/im in browser ,after login now search your "channel".Now in the browser address bar you will one link like https://web.telegram.org/#/im?p=#llliopppppsssssr
p=#llliopppppsssssr after the equal symbol what comes is channel chat ID.
to send message to the telegram "group" without any user intervention , you require a telegram bot. create one using telegram bot-father. take a look at this link. also note the token while creating the bot. This method will work only for telegram Group .Telegram channel another method to be followed which MarxBabu answered below in his answers post.
import requests
# telegram url
url = "https://api.telegram.org/bot<Token>"
def send_mess(text):
params = {'chat_id':-xxxxxxx, 'text': text}
response = requests.post(url + 'sendMessage', data=params)
return response
send_mess(result_you_want_to_send)
to get the chat_id follow the steps mentioned here. note: group chat id's always starts with '-' . e.g. of group chat_id -356163873. A token and chat_id is only what you require to send message to telegram group.
for sending group emails you have to search more as i do not know much
I have it running on a Raspberry pi. You must look for botfather to get your telegram token.
import telepot
from telepot.loop import MessageLoop
telegram_token = 'xxxx:xxxxxx'
user = 4444444
bot = telepot.Bot(telegram_token)
bot.sendMessage(user, 'Hey!')
For configuring gmail I don't have something here right now...
You can send emails in python through SMTP or using the Mailgun Api
I personally prefer using Mailgun as it is easier to setup and sending an email is as easy as sending a post request to mailgun.
You can get the free version of the api and add your group email id to the sandbox (to avoid spam) and then use requests to post an email with the given api token
I am using python slack client to connect and send messages with a bot application.
slc = SlackClient("BOT_USER_TOKEN")
out = slc.api_call(method='users.profile.get', user='XXX')
I am getting not_allowed_token_type error in output json. I am able to call:
slc.api_call(method='chat.PostMessage',channel)
Is there a way to get user email, name from slack API. previously I got the username from event messages. but now I am getting only user id so I am looking for a solution to fetch user info using that id.
The reason you get this error message is that users.profile.get does not work with bot tokens.
To mitigate just use the user token that you received along with your bot token when installing your Slack app.
I want my facebook chatbot to send multiple responses at the same time.
For example:
When the user says:
Hey
The chatbot should respond with:
Hey!
How are you?
Currently using dialogflow and a webhook built using python to build responses.
It is possible. But not in a way I consider clean.
You can add a response under the 'default' tab.
Under the 'facebook' tab you can than tick Use response from the DEFAULT tab as the first response.. This way two responses are send to facebook and to facebook only.
But you can send messages to the messenger via the facebook send api from your webhook at any time. Have a look at: https://developers.facebook.com/docs/messenger-platform/reference/send-api
This has nothing to do with dialogflow though.
You can find the id of the facebook user in the payload, dialogflow send to your webhook.
Here is an example of where you can find it.
{:originalDetectIntentRequest
{:payload
{:source "facebook",
:data
{:recipient {:id "1144092719067446"},
:sender {:id "1235572976569567"}, <== This is the id you are looking for!
:timestamp 1.536065422409E12,
:message
{:mid
"YzKAMwoJlAR0n3Vke2RJf83aVMGWzBnJ77SfUDe_NwkzIT1BBQXaWPVjN6Qf0xN4veairdW504PoKzcKV3lKBw",
:seq 183071.0,
:text "They are loyal"}}},
:source "facebook"},
...
...}
I'm working on a chat application using GAE's Channel API in Python.
I don't think I've set it up correctly. When I leave a page I get the following error message in my browser console:
http://localhost:8080/_ah/channel/dev?command=disconnect&channel=0e0acee3bd…122e0acaa86eeb-channel-1354440420-1452408747-mike|5066549580791808&client=1 400 (Bad Request)
Also, when I send chat message it sends duplicate messages, so I'm guessing users are not being properly disconnected.
I've set it up such that when user visits page, my backend code checks if they are logged in, and if so will automatically create token based on their username and the permalink ID of the page.
I then create a token, calling channel.create_channel method and pass that token as a value in the dict I include when I render my template (Jinja).
In my front-end I open the channel with the token. My on-close function is:
socket.onclose = function(){
connected = false;
}
In my app.yaml file I have included inbound_services: - channel presence.
In my backend code, I have '/_ah/channel/disconnected/'routed to a class that gets that permalink's entity instance, finds the client id from a list of connections and removes that connection from the entity.
Can you someone help me think about the Channel API the right way?
I have a web application in Python that allows someone to post a message. When this occurs, my application will automatically dispatch an email to the other user, who is following the "conversation/post". The user receive the email and replies with a message such as "Ok".
I want capture this reply message to a post in my application. I see this in applications such as Assana. How I can do this? Does there exists a service or API I can use?
Any email sent from the user will go to the domain mail server. If you want to receive it in a POST request, you'll have to write a separate application that retrieves email messages from the mail server and then sends the ones you want in a HTTP request to your web server. You'll then have to run your application as a daemon/service, and have it periodically poll the server for new messages (or use IMAP IDLE)
You may want to use imaplib to retrieve the emails.
Developing a complete two-way bridge between a web page and email with conversation tracking will likely require knowledge about MTA and LDA administration