Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ChatSendMessage problem #1

Open
pooyaostvoar opened this issue Jan 2, 2022 · 3 comments
Open

ChatSendMessage problem #1

pooyaostvoar opened this issue Jan 2, 2022 · 3 comments

Comments

@pooyaostvoar
Copy link

pooyaostvoar commented Jan 2, 2022

I want to make a bot with python. I can get the message from bot and read it but when I want to send a message with API I get <Response [400]>. I used the below code. Is there any problem with my code?

from flask import Flask,request,json
app = Flask(name)
from ChatSendMessage_pb2 import ChatSendMessageResponse, ChatSendMessage
import requests
token = 'my-token'
@app.route('/get_command',methods=['POST'])
def get_command():
data = ChatSendMessageResponse.FromString(request.data)
message = data.room_message.message
room_id = data.room_id
new_message = ChatSendMessage()
new_message.message = 'hi'
new_message.room_id = room_id

data = new_message.SerializeToString()
headers = {
    'content_type':'application/octet-stream',
    'Authorization': "Bearer {}".format(token)
}
res = requests.post(url='https://api.igap.net/botland/v1/api?actionId=201', data=data, headers=headers)
print(res)
return 'ok'

if name == 'main':
app.run(host='0.0.0.0', port=7370, threaded=True, debug=False)

@Amir-m-a
Copy link

Amir-m-a commented Apr 8, 2022

you might need to add this before sending:

from Global_pb2 import RoomMessageType

new_message.message_type = RoomMessageType.TEXT

also try to get more info from response:

from Error_pb2 import ErrorResponse

if res.ok:
    print(ChatSendMessageResponse.FromString(res.content))
else:
    if res.status_code // 100 == 4:
        print(ErrorResponse.FromString(res.content))
    else:
        print(res, res.content)

@erfanoabdi
Copy link

can you please share a simple code on how to read and send msg from bot?
i keep getting <Response [400]> but no action
how to get room id? i assumed it's the same number on web client URL when opening a group https://web.igap.net/app?q=<room id> is that correct?

@h4mid007
Copy link

new_message.message_type = RoomMessageType.TEXT AttributeError: 'EnumTypeWrapper' object has no attribute 'TEXT'

I agree to @erfanoabdi, there isn't any clear explanation & example codes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants